<string name="astring">%d times left<string>java的string中有format方法,你查下sdk吧

解决方案 »

  1.   

    楼主 2楼的方法是正确的,你并不需要判断,只需要 用一个format参数即可。
    如使用你的例子:<string name="astring">%d times left<string>
    在你的java程序中这样使用//Context.getString(int resId, Object... formatArgs)
    int i=1;//value 就是你想要附的值
    getcontext.getString(R.string.astring,i);
      

  2.   


    但是我想值为1时,显示1 time left,值大于1时,显示3 times left
      

  3.   


    //Context.getString(int resId, Object... formatArgs)
    int i=value;//value 就是你想要附的值
    //根据你的需求加个判断条件就行
    getcontext.getString(R.string.astring,i>1?3:i==1?1:0);
    也可这样写
    if(i==1){
    getcontext.getString(R.string.astring,1);
    }
    esle if(i>1){
    getcontext.getString(R.string.astring,3);
    }
    esle{
    //如果小于1呢?do something
    //getcontext.getString(R.string.astring,0);
    }
      

  4.   


    有单复数:time,times
    看来只能再来一条string
      

  5.   

    原来Android里有单复数字符串条件:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <plurals name="numberOfSongsAvailable">
            <item quantity="one">One song found.</item>
            <item quantity="other">%d songs found.</item>
        </plurals>
    </resources>