How to use whole resources in string resources in android

How can I use some integer that I saved in the integers.xml file in the strings.xml file.

For instance:

I have <integer name="some_integer">5</integer> and I would like to use this in the strings.xml file:

<string name="some_string">This is my string num @integers/some_integer in a row</string>

Apparently, my path is not good enough, so I need a little help, please. I believe that there are possible solutions that I simply don’t know about.

Appreciate all the help!

+5
source share
2 answers

the short version is that you cannot 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 string XML

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

so replace %d with the integer you pass to getString

+7
source

Others said your approach does not work. This is an old answer to solve a 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 links:

+3
source

All Articles