SimpleCursorAdapter必须要一个_id字段
2012-05-30 00:06
375 查看
private void pudata() { //cursor=sdb.query("books", new String[]{"id","bookname","price"}, null, null, null, null, null); SQLiteQueryBuilder sqb=new SQLiteQueryBuilder(); sqb.setTables("books"); String returnColumn[]={"books.id as _id","books.bookname","books.price"}; cursor=sqb.query(sdb, returnColumn, null, null, null, null,null); Log.e("", "rows:"+cursor.getCount()); startManagingCursor(cursor); ListAdapter adapter=new SimpleCursorAdapter(this,R.layout.listview,cursor, new String[]{"_id","bookname","price"},new int[]{R.id.listview_id,R.id.listview_name,R.id.listview_price}); lv.setAdapter(adapter); }
使用SimpleCursorAdapter给ListView填充数据时,报异常:
05-29 16:03:17.707: E/AndroidRuntime(28723): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist。
该数据表中并没有_id字段,所以感觉很奇怪。
修改的方式是:在确定查询字段时,可以将主键别名为_id,然后在创建SimpleCursorAdapter时指定该别名即可。
(不过仍然感觉很奇怪,为何非要_id呢?)
相关文章推荐
- SimpleCursorAdapter参数from必须包含_id字段的原因
- simplecursoradapter使用时提示column '_id' does not exist
- SimpleCursorAdapter和_id
- simpleCursorAdapter的一个问题
- sql 查询一个表信息 条件为该表一个字段大于对应(必须该表相对应的Id)另外一个表的总数
- 使用 SimpleCursorAdapter 时java.lang.IllegalArgumentException: column '_id' does not exist问题
- SimpleCursorAdapter和_id
- android中SimpleCursorAdapter _id错误的问题
- android小问题-------------SimpleCursorAdapter使用时的问题。 java.lang.IllegalArgumentException: column '_id' d
- android中SimpleCursorAdapter _id错误的问题
- 继承SimpleCursorAdapter定制Adapter
- mysql把一个表的字段update成另一个表的字段根据id
- Id(int) name(text) 1 网友 2 网友 3 网友 4 网友 5 网友 请写出一个SQL语句,把name字段更新成name+id 也就
- android view类的settag gettag就是在类中加了一个类似id的字段?
- SimpleAdapter 和 SimpleCursorAdapter的使用
- Android采用ListView实现数据列表显示1-使用SimpleCursorAdapter进行数据绑定
- 【android】BasaAdapter不能用了,SimpleAdapter/SimpleCursorAdapter怎么用呢
- Android学习之Adapter:SimpleAdapter,SimpleCursorAdapter,ArrayAdapter(数据库 列表)
- “The constructor SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated”
- 如果要保存的话就必须得一个一个New,因为new一次产生一个id,如果只是在循环外面new是不行的,因为Id是同一个