How to access resource with dynamic name in my case?

前端 未结 5 2005
生来不讨喜
生来不讨喜 2020-12-01 04:02

If I get the image name as a variable like following:

var imageName = SERVICE.getImg();

Then, how can I get the resource with R.drawa

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 04:52

    Try this:

    int id = getResources().getIdentifier(imageName, "drawable", getPackageName());
    

提交回复
热议问题