public int getResource(String name) {
Context ctx = getBaseContext();
int resId = getResources().getIdentifier(name, "id", ctx.getPackageName());
//如果没有在"id"下找到name,将会返回0
return resId;
}
返回id字符串为name的资源ID值