I use multiple lines provided by android-sdk. I used the following code to create a multiple line:
<plurals name="valuestr"> <item quantity="zero">Choose a value.</item> <item quantity="one">%d unit.</item> <item quantity="other">%d units.</item> </plurals>
Java Code:
textView.setText(getResources().getQuantityString(R.plurals.valuestr,0,0));
When I set any value other than '0', it works fine, but when I set '0', it shows '0 unit.' .
Please, help!
Update
When searching on the Internet, I came across a workaround that uses the java.text.MessageFormat class:
<resources> <string name="item_shop">{0,choice,0#No items|1#One item|1<{0} items}</string> </resources>
Then from the code, all you need to do is the following:
String fmt = resources.getText(R.string.item_shop); textView.setText(MessageFormat.format(fmt, amount));
Read more about format strings in javadocs for MessageFormat
source share