Skip to content Skip to sidebar Skip to footer

How To Display Images In Listview Android

I have been looking around for examples on how to do this. Cam across an approach that used SimpleAdapter and HashMaps here on StackOverflow. This is my code. It's not working. All

Solution 1:

The field in your HashMap needs to match. Try this:

listItems = new ArrayList<HashMap<String,Integer>>();
String fieldName = "icon_id";

HashMap<String, Integer> listData1 = new HashMap<String, Integer>();
HashMap<String, Integer> listData2 = new HashMap<String, Integer>();

listData1.put(fieldName, R.drawable.camera_icon_focus_dim);
listData2.put(fieldName, R.drawable.camera_icon_scene_mode);

listItems.add(listData1);
listItems.add(listData2);

SimpleAdapter listItemAdapter = new SimpleAdapter(
    this,
    listItems,
    R.layout.image_list_item,
    new String[] { fieldName },
    new int[] { R.id.listitem_img });

Post a Comment for "How To Display Images In Listview Android"