用SimpleAdapter构造ListView 为什么只显示一项?
privateMap<String,Object>item;privateList<Map<String,Object>>list;privateListViewlv;-...
private Map<String, Object> item;
private List<Map<String, Object>> list;
private ListView lv;
------------------------
public void addData()
{
item = new HashMap<String, Object>();
item.put("title", "Item-1"); item.put("price", "$111");
list.add(item);
item.put("title", "Item-2"); item.put("price", "$112");
list.add(item);
item.put("title", "Item-3"); item.put("price", "$115");
list.add(item);
}
------------------------------------
lv = new ListView(this);
list = new ArrayList<Map<String, Object>> ();
this.addData();
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_1, new String[]{"title"},
new int[]{android.R.id.text1});
lv.setAdapter(adapter);
lv.setOnItemClickListener(listener);
setContentView(lv);
=============
这是部分代码,请帮我看看哪里不对? 展开
private List<Map<String, Object>> list;
private ListView lv;
------------------------
public void addData()
{
item = new HashMap<String, Object>();
item.put("title", "Item-1"); item.put("price", "$111");
list.add(item);
item.put("title", "Item-2"); item.put("price", "$112");
list.add(item);
item.put("title", "Item-3"); item.put("price", "$115");
list.add(item);
}
------------------------------------
lv = new ListView(this);
list = new ArrayList<Map<String, Object>> ();
this.addData();
SimpleAdapter adapter = new SimpleAdapter(this, list,
android.R.layout.simple_list_item_1, new String[]{"title"},
new int[]{android.R.id.text1});
lv.setAdapter(adapter);
lv.setOnItemClickListener(listener);
setContentView(lv);
=============
这是部分代码,请帮我看看哪里不对? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询