private int getIdFromR(String strId, String type, String packageName) {
Resources resources = getResources();
int id = resources.getIdentifier(strId, type, packageName);
return id;
Resources resources = getResources();
int id = resources.getIdentifier(strId, type, packageName);
return id;
}
1.其中 strId:资源name,控件id(@+id/txtview).
2.type:id,drawable,layout等
3.packageName:R.java文件的包名
通过返回的id,然后得到控件或者layout.