Android Resources Define String Plurals

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


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"?>
    <plurals name="hello_people">
        <item quantity="one">Hello to %d person</item>
        <item quantity="other">Hello to %d people</item>

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:


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.

Got any Android Question?