How to set an imageView's image from a string?

前端 未结 4 899
北荒
北荒 2020-11-30 04:02

I have a list of entries and some bitmap files in the res/drawable-mdpi directory. I\'m trying to load the image corresponding to the string value selected from the list by

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 04:33

    No need to use getDrawable() you directly use the resource id like

    String mDrawableName = "myimageName"; int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName()); imgView.setImageResource(resID);

提交回复
热议问题