【发布时间】:2017-02-02 09:49:46
【问题描述】:
我已阅读有关此链接警告的其他帖子,但他们没有解决我的问题,我仍然不明白我做错了什么。
在默认文件strings.xml中,我有:
<string name="rating_dialog">You\'re about to rate this app with %s stars.</string>
稍后,我在覆盖 onClick 方法中调用它:
v.getContext().getString(R.string.rating_dialog, String.valueOf(rating))
它看起来像:
You're about to rate this app with {String.valueOf(rating)} stars.
链接警告:
Format string is not a valid format string so it should not be passed to string.format
注意:
v 是 View,rating 是 int 值。
我检查了其他 strings.xml 文件中的其他语言,所有翻译似乎都正常。
已解决:对于印地语 string.xml,只有 % 而不是 %s。
【问题讨论】:
-
在字符串资源中,您需要使用 %1$s (以及 %2$s 等用于更多变量)
标签: java android string string-formatting getstring