1

I got an odd problem. The getQuantityString() method working on android studio simulator, but not working on the real device.

This is my code in strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <plurals name="subtitle_plural">
        <item quantity="one">%1$s crime</item>
        <item quantity="other">%1$s crimes</item>
    </plurals>
</resources>

code in my Fragment:

CrimeLab crimeLab = CrimeLab.get(getActivity());
int crimeSize = crimeLab.getCrimes().size();
String subTitle = getResources()
                .getQuantityString(R.plurals.subtitle_plural, crimeSize, crimeSize);

When I run the project on the simulator, it works. but if run it on real device, subTitle will always be ** crimes even if crimeSize equals 1.

How did this happen?

Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39
archerLj
  • 199
  • 1
  • 2
  • 14

1 Answers1

0

You should use like that:

CrimeLab crimeLab = CrimeLab.get(getActivity());
int crimeSize = crimeLab.getCrimes().size();
String subTitle = String.format(getResources()
                .getQuantityString(R.plurals.subtitle_plural, crimeSize, crimeSize));
dralexnumber
  • 238
  • 2
  • 10