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

中间找到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();
}

你可能感兴趣的:(android)