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?

2
  • stackoverflow.com/a/12627660/584140 Commented Mar 24, 2017 at 20:44
  • People coming here because they were using \%% you might be able to fix this by simply removing the backslash, %% worked for me Commented Nov 11, 2023 at 13:27

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.