Shankar Prasad Shankar Prasad - 2 months ago 11
Android Question

Concatenate string and integer in string.xml

I am trying to concatenate string and integer in string.xml like below...

<integer name="min_length">10</integer>
<string name="error">Enter minimum @integer/min_length chars</string>


So that the value of getString(R.string.error) could be "Enter minimum 10 chars". But getting error, please help!

Answer

You can not concatenate strings or integer and strings in xml. You can do refer to another string or integer in one string or integer tag respectively in xml , but only one. Like:

 <integer name="min_length">10</integer>

<integer name="min">@integer/min_length</integer>

You can refer integer inside integer and string inside string .

If you try to do what you mentioned above android studio , you will be thrown away with error.

Comments