当前位置: 代码迷 >> Android >> Cursor 怎么循环放到Map里呢
  详细解决方案

Cursor 怎么循环放到Map里呢

热度:29   发布时间:2016-05-01 13:25:36.0
Cursor 如何循环放到Map里呢
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();

while (result.moveToNext()) {
  map.put("name", result.getString(result.getColumnIndex("name")));
  map.put("address", result.getString(result.getColumnIndex("address")));
  list.add(map);
}

SimpleAdapter listadapter = new SimpleAdapter(Show.this, list,
R.layout.show_result, new String[] { "name", "address" },
new int[] { R.id.show_name, R.id.show_address });

这样写,如果输出结果的话,得到的只有最后一条。重复x次(如果数据里有x条记录)


如何能输出全部记录呢??


------解决方案--------------------
在 while 里面 new HashMap

while (result.moveToNext()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", result.getString(result.getColumnIndex("name")));
map.put("address", result.getString(result.getColumnIndex("address")));
list.add(map);
}
  相关解决方案