Android getResources/getIdentifier没有返回ID

Tom*_*Tom 3 android

我有像这样的代码:

String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());
Run Code Online (Sandbox Code Playgroud)

字符串S =指令设置一个值,是相同于我的RES /抽拉-HDPI文件夹名称中的一个.但是,返回值将RID设置为值0

知道为什么我的代码无效吗?难道我做错了什么?

Pra*_*ani 6

试试这个

String s = "replace__menu__" + data.imageid;  // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());
Run Code Online (Sandbox Code Playgroud)