当数据库发生变化时,如何刷新游标适配器?
例如,当我向数据库添加一行时,我运行 ff. code,
Cursor crs = adapterToRefresh.getCursor();
crs.close();
crs = this.dbImmunization.queryAll();
this.startManagingCursor(crs);
crs.moveToFirst();
adapterToRefresh.changeCursor(crs);
adapterToRefresh.notifyDataSetChanged();
其中 crs 是游标适配器内的游标检索。
到目前为止,这个实现给了我一个 CursorIndexOutOfBoundsException 错误。
帮助任何人!
for example, when i add a row to the database, i run the ff. code,
Cursor crs = adapterToRefresh.getCursor();
crs.close();
crs = this.dbImmunization.queryAll();
this.startManagingCursor(crs);
crs.moveToFirst();
adapterToRefresh.changeCursor(crs);
adapterToRefresh.notifyDataSetChanged();
where crs, is the cursor retrieve within the cursor adapter.
so far, this implementation gives me an error of CursorIndexOutOfBoundsException.
Help anyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先使用 sqlite 浏览器查看表和行是否正确创建。第二,当你遍历数据库时,你将如何到达最后一行。可能有问题。只有当你显示 logcat 输出时才会更清楚。
First use the sqlite browser to see the tables and rows if created properly. second when you are traversing the database how you are going to the end row. may be there is the problem. It will be clearer only when u show your logcat output.
您已经调用了startManagingCursor(cursor),因此您不需要调用adapter.notifyDataSetChanged()。相反,当您需要刷新其查询和获取的数据时,请调用cursor.requery()。
You have called the startManagingCursor(cursor), therefore you don't need to call adapter.notifyDataSetChanged(). Instead, call cursor.requery() when you need to refresh its query and fetched data.