Show plurals on Android

0

Is there any way to pluralize strings in Android? that is, to represent.

hay 1 objeto
hay 3 objetos

Currently what I do is have two resources defined in string.xml and if the value is more than 1 charge one or the other.

    
asked by Webserveis 10.12.2016 в 18:00
source

1 answer

3

I think if you do not want to use 2 resources you can go all in 1, I mean

 <string name="huevos">hay %1$d %2$d</string>

Where %2$d can be Egg or Eggs

Or in this way

<plurals name="numeroHuevos">
<item quantity="one">hay %d huevo</item>
<item quantity="other">hay %d huevos</item>
</plurals>

EDIT

int count = getCountHuevoa();
Resources res = getResources();
String cantidadHuevos =  res.getQuantityString(R.plurals.numeroHuevos, count, count);
    
answered by 10.12.2016 / 18:43
source