<span style="white-space:pre"> </span>listView = (ListView) findViewById(R.id.list) ;
//生成动态数组,加入数据
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
//map.put("ItemImage", R.drawable.icon);//图像资源的ID
map.put("ItemTitle", i);
map.put("ItemText", "goods ");
listItem.add(map);
}
//生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdapter = new SimpleAdapter(this,
listItem, <span style="white-space:pre"> </span>//数据源
R.layout.msgitem, //ListItem的XML实现
new String[] {"ItemImage","ItemTitle", "ItemText"}, <span style="white-space:pre"> </span><span style="font-family: Arial, Helvetica, sans-serif;">//动态数组与ImageItem对应的子项 </span><span style="white-space:pre">
</span>
new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText} <span style="white-space:pre"> </span><span style="font-family: Arial, Helvetica, sans-serif;">//ImageItem的XML文件里面的一个ImageView,两个TextView ID</span><span style="white-space:pre">
</span>
);
//添加并且显示
listView.setAdapter(listItemAdapter);
转载于:https://www.cnblogs.com/jasonkent27/p/4098418.html
相关资源:listview数据重复解决办法