本文介绍了如何显示的ListView android的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在四处寻找如何做到这一点的例子。跨使用SimpleAdapter和HashMaps这样在这里StackOverflow的做法凸轮。
这是我的code。它不工作。所有我能看到的是一个列表的空行。
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 I can see is an empty row of a list.
listItems = new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> listData1 = new HashMap<String,Object>();
HashMap<String,Object> listData2 = new HashMap<String,Object>();
image_1 = getResources().getDrawable(R.drawable.camera_icon_focus_dim);
image_2 = getResources().getDrawable(R.drawable.camera_icon_scene_mode);
listData1.put("icon focus", image_1);
listData2.put("icon_scene", image_2);
listItems.add(listData1);
listItems.add(listData2);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItems,
R.layout.image_list_item, new String[]{"icon_focus"},
new int[]{R.id.list_view_item1});
optionsList.setAdapter(listItemAdapter);
image_list_item.xml:
image_list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="12dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listitem_img"
/>
list_item.xml:
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view_item1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1.0"
/>
请告诉我,我做错了。
推荐答案
在的HashMap
需要匹配的字段。试试这个:
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 });
这篇关于如何显示的ListView android的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!