How can I concatenate static strings with XML string resources?
Sorry, no such syntax is supported by Android resource files.
Using XML entities it's possible.
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE resources [ <!ENTITY mintues "minutes"> <!ENTITY minute "minute"> <!ENTITY seconds "seconds">]><resources> <string-array name="interval_labels"> <item>30 &seconds;</item> <item>1 &minute;/item> <item>5 &minutes;</item> <item>10 &minutes;</item> <item>15 &minutes;</item> <item>30 &minutes;</item> <item>60 &minutes;</item> </string-array></resources>
I used this answer: dynamic String using String.xml?
There is a way of sort-of getting this effect, by defining the string resource with a place holder and using String.format()
style overload of getResourses().getString()
in the code behind:
In string.xml
<string name="secs">%1$d seconds</string>
In activity_layout.xml
<TextView android:id="@+id/secs_label" />
In TheActivity.java
((TextView)findViewByID(R.id.secs_label)).setText(getResources().getString(R.string.secs, 25));