? - xml中string怎么动态添加程序中的值 <string name="astring">%d times left<string>java的string中有format方法,你查下sdk吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主 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); 但是我想值为1时,显示1 time left,值大于1时,显示3 times left //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);} 有单复数:time,times看来只能再来一条string 原来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> ●●android上传文件问题,请高手指点迷津,在线等 getSystemService 异常 快崩溃了 DatePicker类型转换问题 有关widget的问题,急啊............... 求教:短信拦截模拟器正常运行,为何在真机上一收到短信就挂了~? 如何傳遞實時同步視頻串流到網路伺服器 android如何使用webview设置页面中含有返回键 android下的触摸屏事件 如何学好android游戏开发? 服务器端如何提取客户端POST的数据 Android安装包及程序所用配置文件相关问题 如何读取内存文件?不是SDCard!
如使用你的例子:<string name="astring">%d times left<string>
在你的java程序中这样使用//Context.getString(int resId, Object... formatArgs)
int i=1;//value 就是你想要附的值
getcontext.getString(R.string.astring,i);
但是我想值为1时,显示1 time left,值大于1时,显示3 times left
//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);
}
有单复数:time,times
看来只能再来一条string
<?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>