How to use integer resources within string resources in android How to use integer resources within string resources in android xml xml

How to use integer resources within string resources in android


short version is that you can't mix resources like this, but you can use in Java:

getResources.getString(R.string.some_string,                       getResources.getInteger(R.integer.some_integer)                      );

and then in your String XML

<string name="some_string">This is my string num %d in a row</string>

that way the %d get replaced by the integer you pass in the getString


Others said your approach do not work. This is an old answer to face similar problem:

<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);

See this references: