80,362
社区成员
发帖
与我相关
我的任务
分享
private static Class<?> mId = null;
public static int id(Context c, String name) {
if (mId == null) {
try {
mId = Class.forName(c.getPackageName() + ".R$id");
}catch (ClassNotFoundException localClassNotFoundException) {
localClassNotFoundException.printStackTrace();
return -1;
}
}
try {
Field localField = mId.getField(name);
int i = localField.getInt(name);
return i;
} catch (Exception localException) {
localException.printStackTrace();
}
return -1;
}