I have written the line:
String Mess = R.string.mess_1 ;
to get string value, but instead of returning string, it is giving me id of type integer. How can I get its string value? I mentioned the string value in the string.xml
file.
I have written the line:
String Mess = R.string.mess_1 ;
to get string value, but instead of returning string, it is giving me id of type integer. How can I get its string value? I mentioned the string value in the string.xml
file.
In Activity:
If not in activity but have access to context:
By the way, it is also possible to create string arrays in the strings.xml like so:
And then from your Activity you can get the reference like so:
**
**
Try this
UPDATE
You can use either
getString(int)
orgetText(int)
to retrieve a string.getText(int)
will retain any rich text styling applied to the string.Reference: https://developer.android.com/guide/topics/resources/string-resource.html
Only for future references.
In the String resources documentation it says:
You must reference Context name before using
getResources()
in Android.OR