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

前端 未结 4 895
北荒
北荒 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:16

    You can Create Common Function for getting image drawable like this:

    public static Drawable getDrawable(Context mContext, String name) {
            int resourceId = mContext.getResources().getIdentifier(name, "drawable", mContext.getPackageName());
            return mContext.getResources().getDrawable(resourceId);
        }
    

提交回复
热议问题