getQuantityString not replacing the format with the value
AndroidAndroid Problem Overview
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"
?
Android Solutions
Solution 1 - Android
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 to getQuantityString
.
ie res.getQuantityString(R.plurals.numberOfSongsAvailable, count, count);
Solution 2 - Android
Just in case anyone has a brain-fail like me today and still cannot get it working.
I had accidentally left my emulator in a non-English locale which meant my "one" translation was being ignored!
(Only the "other" entry was being used in my case)