What's wrong with this format string? What's wrong with this format string? android android

What's wrong with this format string?


Your string should be

<string name="q_title" formatted="false">Item %1$d of %2$d</string>

And code

String log = getString(R.string.q_title, 100, 500);

When you have multiple arguments you need to mark them with 1$, 2$... n$. In arabian langs order is reversed, so they need to know how to change it correctly.

getString(id, args...) perform format in itself.


For percent, the following worked for me.

<string name="score_percent">%s%%</string>getString(R.string.score_percent,"20")

If you are dealing with integers replace s by d

<string name="score_percent">%d%%</string>


For those still looking for this answer, as the link that Blackbelt posted implies, the correct format for the string would be:

<string name="q_title">Item %1$d of %2$d</string>