通过代码的string name 找到到value下对应的string name

来源:互联网 发布:中国海洋渔业知乎 编辑:程序博客网 时间:2024/06/10 11:42

中间找到R 中的id,从而找到value下的string context


try {

Field field = R.string.class.getField("hello");


try {
int id = field.getInt(new R.string());
Log.d("pin2", "id:" + id);


String str = getString(id);
Log.d("pin2", "str:" + str);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
0 0
原创粉丝点击