sqlite查询结果在listview中展示的实现
时间:2021-08-12 09:32:09|栏目:Android代码|点击: 次
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);
上一篇:Android中一种巧妙的drawable.xml替代方案分享
栏 目:Android代码
下一篇:Android显式启动与隐式启动Activity的区别介绍
本文标题:sqlite查询结果在listview中展示的实现
本文地址:http://www.codeinn.net/misctech/166367.html