【发布时间】:2012-04-16 08:32:35
【问题描述】:
String res = "R.drawable.image1";
我需要得到它的 INT id。请帮帮我!
【问题讨论】:
标签: java android string resources int
String res = "R.drawable.image1";
我需要得到它的 INT id。请帮帮我!
【问题讨论】:
标签: java android string resources int
使用它来获取资源ID:
int picId = getResources().getIdentifier(picName, "drawable", getApplicationContext().getPackageName());
【讨论】:
如果您想获得integer,则只需删除引号即可。
int id = R.drawable.image1; // instead of "R.drawable.image1"
这会给你号码。
【讨论】:
View view = findViewById(R.drawable.image1);
int id = view.getId();
【讨论】:
R.drawable.image1...你使用了一个已有的ID,然后找到它,然后取回它