4

I want to display such a title in my screen, "Up to 30% cheaper".

So, I have this in my xml file: <string name="title">Up to %d%% cheaper</string>

and In code: mTitle.setText(getString(R.string.title, 30));

Although it works fine and I see above message however I am getting lint error that says:

enter image description here

How to get rid of this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Hesam
  • 52,260
  • 74
  • 224
  • 365

2 Answers2

1

I just ran into the same problem, and found out how to resolve it: You need to assign a position to your replacement strings. So instead of %d%%, you'd have to use %1$d%% (the %1 denotes the position and the $d specifies the type). Also, contrary to what one would expect, formatted="false" does NOT remove the warning. In fact, only after I removed that part, the warning went away.

techfly
  • 1,826
  • 3
  • 25
  • 31
0

Try this: <string name="title">Up to %1$d%% cheaper</string>

shmakova
  • 6,076
  • 3
  • 28
  • 44
  • Thanks for your help, but I tried that before and no difference. basically 1$ uses when there are multiple arguments otherwise there isn't any difference. – Hesam Mar 24 '17 at 21:02