Define String Plurals

suggest change

To differentiate between plural and singular strings, you can define a plural in your strings.xml file and list the different quantities, as shown in the example below:

<?xml version="1.0" encoding="utf-8"?>
<resources>  
    <plurals name="hello_people">
        <item quantity="one">Hello to %d person</item>
        <item quantity="other">Hello to %d people</item>
    </plurals>
</resources>

This definition can be accessed from Java code by using the getQuantityString() method of the Resources class, as shown in the following example:

getResources().getQuantityString(R.plurals.hello_people, 3, 3);

Here, the first parameter R.plurals.hello_people is the resource name. The second parameter (3 in this example) is used to pick the correct quantity string. The third parameter (also 3 in this example) is the format argument that will be used for substituting the format specifier %d.

Possible quantity values (listed in alphabetical order) are:

few
many
one
other
two
zero

It is important to note that not all locales support every denomination of quantity. For example, the Chinese language does not have a concept of one item. English does not have a zero item, as it is grammatically the same as other. Unsupported instances of quantity will be flagged by the IDE as Lint warnings, but won’t cause complication errors if they are used.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents