R.string获取的是数字或者R.integer数字不对的问题

String msg = R.string.menu_title;

获取menu_title的String值,但发现这样写报错,原因R.string.menu_title是int类型的,可是通过以下方式确可以获取。

TextView TV = new TextView(this);
TV.setText(R.string.menu_about_content);
 
解决问题:
R类只是保存资源的ID,是整形数字。
除了你写的方法可以设置外还可以通过如下代码直接获取
getResources().getString(R.string.menu_about_content)
如果R.string.menu_about_content是数字,可以通过
getResources().getInteger(R.string.menu_about_content)
其它的类型也类同。
原文地址:https://www.cnblogs.com/netcorner/p/4628498.html