Working with Plurals in Android

Sree Kumar A.V
Jul 19, 2021

Most of the time you have to work with plurals while building the app. Android provides a convenient way to deal with them more elegantly.

Here is an example.

  • When quantity is 1 one
    You have an Appointment today
  • When quantity is more than one
    You have appointments today

You can use the getQuantityString API to deal with plurals.

What if, you have to add quantity when its plural

You have 3 appointments today

If you look closer to the getQuantityString API

Quantity decides which string to choose (singular vs plural) and the last one is format arguments, which is used for substitution.

How to refer plurals through Data binding

android:text=”@{@plurals/appointment_messsage(Integer.valueOf(count))}”

Thanks for reading !!

--

--