3

我有这样的代码:

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

String s =指令设置的值与我的 res/drawable-hdpi 文件夹中的名称之一相同。但是,返回值将RID设置为值0

知道为什么我的代码不起作用吗?难道我做错了什么?

4

2 回答 2

6

试试这个

String s = "replace__menu__" + data.imageid;  // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());
于 2013-05-28T13:18:48.693 回答
3
".png" is not part of a ressource name
"drawable-hdpi" I would try just 'drawable' instead 
于 2013-05-28T13:20:46.663 回答