How to use plurals in android ?

Different languages have different rules for grammatical agreement with quantity. In English, for example, the quantity 1 is a special case. We write “1 book”, but for any other quantity we’d write “n books”. This distinction between singular and plural is very common, but other languages make finer distinctions. The full set supported by Android is zero, one, two, few, many, and other.


<plurals name="numberOfSongs">
<item quantity="one">one song found.</item>
<item quantity="other">%d songs found.</item>
</plurals>

in Java class we can get values as shown below:

int count = getNumberOfsongsAvailable();
Resources res = getResources();
String songsFound = res.getQuantityString(R.plurals.numberOfSongsAvailable, count, count);

For more reference follow this link here.

Advertisements

Tags: , , , , , , , ,

About A.Ramesh

I am enthusiastic mobile developer, self motivated. Keen interest to learn new technologies and excited to share what I have learnt throughout my work experience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: