我有这样的代码:
String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());
String s = 指令设置了一个与我的 res/drawable-hdpi 文件夹中的名称之一相同的值。但是,返回值将 RID 设置为值 0
知道为什么我的代码不起作用吗?我做错了什么吗?
最佳答案
试试这个
String s = "replace__menu__" + data.imageid; // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());
关于Android getResources/getIdentifier 不返回 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16793081/