Android: double value string format in Strings.xml

I need to create a String using Formater in order to display some double values ​​in an application. I do not understand how to encode it. Here is what I have:

<string name="diseaseMessage">You have %s message, Unread %s</string>

I get this error:

error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?  
error: Unexpected end tag string    strings.xml /TSMS Pro/res/values    line 70 Android AAPT Problem
+4
source share
1 answer
<string name="diseaseMessage">You have %1$s message, Unread %2$s</string>

From Android docs:

String formatting

If you need to format strings using String.format (String, Object ...) , you can do this by putting your format arguments in the string resource. For example, with the following resource:

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

In this example, a format string has two arguments:% 1 $ s is a string, and% 2 $ d is a decimal number. You can format the string with arguments from your application as follows:

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
+3

All Articles