Is it possible to use an integer:
<integer name="minstringlength">7</integer>
within the same resource file but within a string:
<string name="nametooshort">Please enter a name longer than @integer/minstringlength characters</string>
Is it possible to use an integer:
<integer name="minstringlength">7</integer>
within the same resource file but within a string:
<string name="nametooshort">Please enter a name longer than @integer/minstringlength characters</string>
I presume you want to use different minimum limits based on device configuration. You can't use the @integer/minstringlength
in the string content, so I think the best you can do is have a format argument and build the string yourself like this:
<integer name="minstringlength">7</integer>
<string name="nametooshort">Please enter a name longer than %1$d characters</string>
int nameMinLength = getResources.getInt(R.integer.minstringlength, 0);
String nametooshort = getString(R.string.nametooshort, nameMinLength);
This assumes you are using an Activity/Fragment, otherwise you need a Context
in order to use getResources()
and getString()
.
It can not be done in resource file.
As xml contains static content and also from android string-resource doc there is no sub tag or nested tag of <string>
It task can done easily in java file
getResources().getString(R.string.minstringlength);
getResources().getInteger(R.integer.nametooshort);
<string name="meatShootingMessage">You shot %1$d pounds of meat!</string>
int numPoundsMeat = 123;
String strMeatFormat = getResources().getString(R.string.meatShootingMessage);
String strMeatMsg = String.format(strMeatFormat, numPoundsMeat);