安卓报错 column '_id' does not exist 的解决

来源:互联网 发布:淘宝老a的店铺 编辑:程序博客网 时间:2024/05/01 00:10

在安卓开发过程中需要一个简单的搜索功能,搜索过程需要根据输入的字符,从数据库中选出可能匹配的项,先显示出来。

使用 SimpleCursorAdapter 来实现动态显示列表的功能

SimpleCursorAdapter mAdapter;Cursor cursor;cursor = database.query("Notes",new String[] {"id as _id","pictureName","contentName"},null,null,null,null,null);mAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,new String[] {"contentName","pictureName"}, new int[] { android.R.id.text1 },                0);

注意 id as _id。
使用SimpleCursorAdapter 需要数据库的表中有名为 _id 的列,可以手动去修改原来数据库的表,增加_id 列。若已经有类似 id 的自增的列,那么可以在查询时,加入 “ id as _id”

0 0
原创粉丝点击