如何将读取出来的数据放到listview中
2017-01-18
展开全部
如何将读取出来的数据放到listview中
final SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.mainlayout, new String[] { "text", "time", "image"告返链 },
new int[] { R.id.PL_TextView01, R.id.PL_TextView02,
R.id.PL_ImageView01 });
lv.setAdapter(adapter);
private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
Cursor cur = DR.query("DB", new String[] { "text", "time" }, null,
null, null, null, "time desc");
while (cur.moveToNext()) {
for (int i = 0; i < cur.getCount(); i++) {
cur.moveToPosition(i);
String text = cur.getString(0);
String time = cur.getString(1);
map = new HashMap<String, Object>();
map.put("text", text);
map.put("time", time);
map.put("image", R.drawable.ic_menu_close_clear_cancel);
list.add(map);
}
}
return list;
}
我是使用SimpleAdapter 作为世桐listview的适配器 通过袜孙数据的query方法 将数据放入listview
final SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.mainlayout, new String[] { "text", "time", "image"告返链 },
new int[] { R.id.PL_TextView01, R.id.PL_TextView02,
R.id.PL_ImageView01 });
lv.setAdapter(adapter);
private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
Cursor cur = DR.query("DB", new String[] { "text", "time" }, null,
null, null, null, "time desc");
while (cur.moveToNext()) {
for (int i = 0; i < cur.getCount(); i++) {
cur.moveToPosition(i);
String text = cur.getString(0);
String time = cur.getString(1);
map = new HashMap<String, Object>();
map.put("text", text);
map.put("time", time);
map.put("image", R.drawable.ic_menu_close_clear_cancel);
list.add(map);
}
}
return list;
}
我是使用SimpleAdapter 作为世桐listview的适配器 通过袜孙数据的query方法 将数据放入listview
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询