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.
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.
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);