how to read value from string.xml in android?

UMAR-MOBITSOLUTIONS picture UMAR-MOBITSOLUTIONS · Feb 2, 2010 · Viewed 358.6k times · Source

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.

Answer

ccheneson picture ccheneson · Feb 2, 2010

Try this

String mess = getResources().getString(R.string.mess_1);

UPDATE

String string = getString(R.string.hello);

You can use either getString(int) or getText(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