我的代码类似于:
String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());
String s = 指令设置的值与res / drawable-hdpi文件夹中的名称之一相同。但是,返回值将 RID 设置为值 0
知道为什么我的代码无效吗?我做错了吗?
答案 0 :(得分:6)
试试这个
String s = "replace__menu__" + data.imageid; // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());
答案 1 :(得分:3)
".png" is not part of a ressource name
"drawable-hdpi" I would try just 'drawable' instead