如果我得到的图像的名字像下面的变量:
VAR imageName = SERVICE.getImg();
然后,我怎么能得到与 R.drawable资源。????
,我试过 R.drawable [imageName]
,但是失败了。有什么建议?
内部ID = getResources()则getIdentifier(imageName,类型,封装)。
This将让你你正在寻找的资源的ID 。有了它,你就可以从R类访问的资源。
If I get the image name as a variable like following:
var imageName = SERVICE.getImg();
Then, how can I get the resource with R.drawable.????
, I tried R.drawable[imageName]
, but it failed. Any suggestions?
int id = getResources().getIdentifier(imageName, type, package);
This will get you the ID of the resource you are looking for. With it, you can then access the resource from the R class.