getQuantityString返回值为0的错误字符串 [英] getQuantityString returns wrong string with 0 value

查看:172
本文介绍了getQuantityString返回值为0的错误字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个Android应用中,我具有以下字符串资源:

In an android app, I have the following string resources:

<plurals name="test">
   <item quantity="zero">"I have 0 item"</item>
   <item quantity="one">"I have 1 item"</item>
   <item quantity="other">"I have several items"</item>
</plurals>

以及以下代码行:

String text = getResources().getQuantityString(R.plurals.test, 0)

我希望返回

我有0件物品

I have 0 item

但是它实际上会返回

我有1个物品

I have 1 item

为什么?

推荐答案

在某些平台和电话上,数量字符串被破坏为应复数和使用数量字符串".指出.这取决于您无法控制的许多因素(例如手机上的本地化).

Quantity Strings are broken on some Plattforms and phones as the issue Tracker and this discussion "Should Plurals and Quantity Strings be used" points out. It depends on many factors which you cannot control (i.e. localization on the phone).

一种解决方案可以是采用类似于该库的外部库,该库具有相同的功能

One solution can be to take an external library like this one, which mimes the same functionallity.

另一种解决方案在android中的复数形式文档中提出.避免使用它,而使用数量中立"的表述,例如"Books:1"

Another solution is stated in the documentation of plurals in android. Avoid using it and use "quantity-neutral" formulations like "Books: 1"

这篇关于getQuantityString返回值为0的错误字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆