Dynamically show images from resource/drawable

后端 未结 3 884
孤独总比滥情好
孤独总比滥情好 2021-01-06 13:22

I\'m trying to put different images (.jpg , .png) dynamically into a ListView from res/drawable . The names from the images I get from a database.

3条回答
  •  北海茫月
    2021-01-06 13:27

    The simple adapter expects String in the map. But your map contains a drawable for the key "img".

    Instead try extending the BaseAdapter class. Override the getView method and then manually set the drawable to the imageview and text to textview.

    Another thought, it might not be a good idea to keep every drawable in memory. Rather get the drawable dynamically while rendering that particular row of the list

提交回复
热议问题