怎么将sqlite的查询结果显示在listview中

本篇文章为大家展示了怎么将sqlite的查询结果显示在listview中,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

1、获取db实例

SQLiteDatabase db=dbhelper.getWritableDatabase(); 

2、Cursord对象获取查询结构

Cursor cursor=db.rawQuery("select * from good where number>3",null); 

3、新建SimplecursorAdapter对象

SimpleCursorAdapter cursorAdapter=new SimpleCursorAdapter(this, R.layout.golist_item, cursor, new String[]{"_id","name", "price","number"},new int[]{R.id.textView2,R.id.textView3,R.id.textView4,R.id.textView1},CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); 

simplecusoradapter的构造方法有6个参数(上下文环境,listview布局文件,游标,列名(new string[]{}),显示内容(new int[]{}),flag设置监听)

4、setadapter(cursorAdapter);

上述内容就是怎么将sqlite的查询结果显示在listview中,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。