小编And*_*ndy的帖子

如何使用Android数量字符串(复数)?

我试图在参考资料中使用getQuantityString方法来检索基于android开发人员指南的数量字符串(复数)数量字符串(复数)

我得到的错误是

Error:(604) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?
Error:(604) Found tag </item> where </plurals> is expected
Run Code Online (Sandbox Code Playgroud)

当我设置复数如下

<plurals name="productCount">
    <item quantity="one" formatted="true">%1$d of %2$d product</item>
    <item quantity="other" formatted="true">%1$d of %2$d products</item>
</plurals>
Run Code Online (Sandbox Code Playgroud)

并尝试阅读如下

productIndexCountText.setText(getResources().getQuantityString(R.plurals.productCount, position, size));
Run Code Online (Sandbox Code Playgroud)

一种解决方法是将字符串分解为仅对字符串的最后部分使用复数并连接这两部分.但我试图尽可能避免这样做.

string android plural android-resources

23
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-resources ×1

plural ×1

string ×1