I want to uses the plurals resource to produce a quoted number like "9"
.
In my plurals.xml
:
<plurals name="posts"> <item quantity="other">\"%dd\"<\item> </plurals>
The code:
String text = res.getQuantityString(R.plurals.posts, meUser.postCount);
When the postCount
is 9, why does text
turn out to be "%dd"
and not "9"
?
Multiple quantities in one string If your display text has multiple quantities, e. g. %d match(es) found in %d file(s). , split it into three separate resources: %d match(es) ( plurals item) %d file(s) ( plurals item)
This enables you to define different strings based on the number of items you refer to. For example, in English you would refer to "one Android" but "seven Androids". By creating a plurals resource, you can specify an alternative string for any of zero, one, multiple, few, many, or other quantities.
String Array. XML resource that provides an array of strings. Quantity Strings (Plurals) XML resource that carries different strings for pluralization. All strings are capable of applying some styling markup and formatting arguments.
From the Android docs:
When using the
getQuantityString()
method, you need to pass the count twice if your string includes string formatting with a number. For example, for the string%d
songs found, the first count parameter selects the appropriate plural string and the second count parameter is inserted into the%d
placeholder. If your plural strings do not include string formatting, you don't need to pass the third parameter togetQuantityString
.
ie res.getQuantityString(R.plurals.numberOfSongsAvailable, count, count);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With