Let's say I have this string:
Your player has a good keeper skill and a decent people skill
Now the part not in bold of the string is always the same, what is known at runtime is the part in bold.
So how could I do something like:
Your player has a {var1} keeper skill and a {var2} people skill
and then fill those vars at runtime with right values?
I do not want to concatenate strings like:
"You player has a" + var1 + "keeper skill and a" + var2 + "people skill"
You need to see Android string resource guide. There is a way to provide static string which can be later formatted with variables.
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
You will define string like
<resources>
<string name="welcome_messages">Hello, %1$s! You have <b>%2$d new messages</b>.</string>
</resources>
And later in code you can replace
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
CharSequence styledText = Html.fromHtml(text);
in Strings.xml
You player has a %1$d keeper skill and a %2$d people skill
in java
getString(R.string.article_stats, var1, var2);
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