根據圖片名獲取ID

public int getResourceId(String name){
try {
//根據資源的ID的變量名得到Field的對象,使用反射機制來實現的
Field field = R.drawable.class.getField(name);
//取得並返回資源的id的字段(靜態變量)的值,使用反射機制
return Integer.parseInt(field.get(null).toString());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return 0;
}
web