I want to create the following string array in my strings.xml
file:
<string-array name="an_array_columns"> <item>% Select percentage1</item> <item>% Select percentage2</item> </string-array>
here the string is "% select percentage". Now, when I am writing this in my strings.xml, I am getting the following 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
I know we can change &
to &
or '
to \'
, but what do I do for percentage sign?
Note: A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). So, you can combine string resources with other simple resources in the one XML file, under one <resources> element. file location: res/values/filename.xml. The filename is arbitrary.
xml , you can easily translate your whole app into other languages. This saves you a lot of work instead of doing this the hardcoded way: Android automatically selects the correct language based on user preferences, and you don't have to worry about selecting and displaying this language.
In android studio, you can simply press Alt+Enter and it will convert for you.
Just use getText(R. string.
%%
seems to be all that works for me. For example:
<string name="num_percent">%1$d %%</string>
with
String oneHundredPercentString = getString(R.string.num_percent, 100); // This gives "100 %"
You can use its code. Try this: %
Also check the similar question: Android XML Percent Symbol
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With