how to read value from string.xml in android?

2019-01-03 03:55发布

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.

16条回答
Rolldiameter
2楼-- · 2019-01-03 04:51

You can use this code:

 getText(R.string.mess_1); 

Basically, you need to pass the resource id as a parameter to the getText() method.

查看更多
乱世女痞
3楼-- · 2019-01-03 04:53

getString(R.string.your_string) get the result

查看更多
太酷不给撩
4楼-- · 2019-01-03 04:58

I'm using this:

String URL = Resources.getSystem().getString(R.string.mess_1);
查看更多
爷的心禁止访问
5楼-- · 2019-01-03 05:00

If you are in an activity you can use

getResources().getString(R.string.whatever_string_youWant);

If you are not in an Activity use this :

getApplicationContext.getResource().getString(R.String.Whatever_String_you_want)
查看更多
登录 后发表回答