Variables can be included in the strings defined in strings.xml using the C-style printf '%' syntax. This is because getString passes the string through java.util.Formatter.
In the example above, getString substitutes %d for the integer 10 in the string message.
This tip was taken from Bram Borggreve's blog ( bVirtual.nl ).
// In strings.xml
<string name="unread_messages">You have %d unread messages</string>
// In Java code
String message = getString(R.string.unread_messages, 10);
Be the first to comment