Is it possible to have placeholders in string values in string.xml
that can be assigned values at run time?
Example:
some string PLACEHOLDER1 some more string
Is it possible to have placeholders in string values in string.xml
that can be assigned values at run time?
Example:
some string PLACEHOLDER1 some more string
You can use
MessageFormat
In Java code :
API level 1:
https://developer.android.com/reference/java/text/MessageFormat.html
In Kotlin you just need to set your string value like this:
Create a text view on your layout:
Then do this in your code if you using Anko:
You might need to get your resources from the application context.
However, you should also read Elias Mårtenson's answer on Android plurals treatment of “zero”. There is a problem with the interpretation of certain values such as "zero".