I have an array of strings in which the %
symbol is used. Proper format for using the %
is %
. When I have a string in that array with multiple %
it gives me this error.
Multiple annotations found at this
line:
- error: Multiple substitutions specified in non-positional format;
did you mean to add the formatted="false" attribute?
- error: Found tag </item> where </string-array> is expected
Try using a backslash in front of it, like below:
Use
<string name="win_percentage">%d%% wins</string>
to get
80% wins
as a formatted string.I'm using
String.format()
method to get the number inserted instead of%d
.Suppose you want to show (50% OFF) and enter 50 at runtime. Here is the code:
In the java class use this code:
You can escape the % in xml with %%, but you need to set the text in code, not in layout xml.
To allow the app using formatted strings from resources you should correct your xml. So, for example
should be replaced with
You can see this for details.
Try this one (right):