Is there anyone knows how to refer to a defined string in a string definition, i.e.:
<string name="string_1">I am string 1</string>
and then,
<string name="string_2">I want to refer to @string/string_1</string>
<string name="string_3">@string/string_1 need to be referred here</string>
I've tried the sample codes, but it didn't work!
You could try using String.format()
:
<string name="string1">I am %1$s</string>
<string name="string2">String 1</string>
...
String string1 = String.format(resources.getString(R.string.string1, R.string.string2));
Yes you can do it at one condition as long as you reference the entire string
<string name="string_1">I am string 1</string>
<string name="string_2">I am string 2</string>
and then,
<string name="string_2">@string/string_1</string>
<string name="string_3">@string/string_2</string>
<string name="string_default">@string/string2</string>
but following is not supported
<string name="string_default">@string/string1 TEST</string>
You can also get your issue resolved by using String.format()
(a good walk around)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With