liuxinxin_0822 2016-06-01 08:36 采纳率: 0%
浏览 2239

怎么从数据库中取出数据放入listview

final SQLiteDatabase db = openOrCreateDatabase("record",MODE_PRIVATE,null);

    ListView listView=(ListView)findViewById(R.id.listView);    
    map_list=getDataSource(db);

    SimpleAdapter adapter = new SimpleAdapter(this,map_list,R.layout.listview,
            new String[] { "time", "time1","type","type1","money","money1"},
            new int[] { R.id.textView1,R.id.textView2,R.id.textView3,R.id.textView4,R.id.textView5,R.id.textView6});
    listView.setAdapter(adapter);

public static List> getDataSource(SQLiteDatabase db) {
List> map_list = new ArrayList>();
Map map = new HashMap();
Cursor cursor = db.rawQuery("select * from record where name = ?",new String[] {name} );

    while (cursor.moveToNext()) {
            String type =  cursor.getString(2);
            String money = cursor.getString(1);

            map = new HashMap<String, String>();
            map.put("time", "时间:");
            map.put("time1", time);
            map.put("type", "类型:");
            map.put("type1", type);
            map.put("money", "金额:");
            map.put("money1", money);
            map_list.add(map);
    }
    return map_list;
}

cursor就是出错,麻烦帮忙看下哪里出错
  • 写回答

1条回答 默认 最新

  • 斯密德 2016-06-01 09:08
    关注

    1,兄弟,代码的问题,应该很简单,你可以debug下,看各个变量的值

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?