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 !!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sree Kumar A.V
Sree Kumar A.V

Written by Sree Kumar A.V

Lead Android Software Engineer @ YML

No responses yet

Write a response