如果不推荐重新查询,现在如何重新查询游标?
根据标题,如果我们曾经调用 cursor.requery()
,但现在已弃用。现在怎么调用这个函数呢?
此方法已被弃用。 不要使用这个。只需请求一个新光标,这样您就可以异步执行此操作,并在新光标返回后更新您的列表视图。
那么如何请求一个新游标并将其传回适配器呢?
As per the title, if we used to call cursor.requery()
, but it is now deprecated. How do you call this function now?
This method is deprecated.
Don't use this. Just request a new cursor, so you can do this asynchronously and update your list view once the new cursor comes back.
So how does one request a new cursor and pass it back to the adapter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当执行任何 DML 查询时重新初始化游标。
另请参阅此。
Re-initialize cursor when your any DML query execute.
See also this.
想象一下您需要一次又一次使用光标的块。用查询填充它。使用它,然后在重用之前关闭
Just think about a block where you need to use cursor again and again. Populate it with the query. Work with it and then close before reusing
使用 Loader 来管理光标。它将根据需要返回一个新的 Cursor,您可以在适配器上使用
swapCursor()
来刷新数据。Use a Loader to manage your cursors. It will return a new Cursor as needed and you can use
swapCursor()
on the adapter to refresh the data.我使用了ListAdapter.notifyDataSetChanged();当列表内容更改时,这仅适用于列表(如 ArrayList)。
使用数据库输出,它不再起作用了。因此我采用了 cursor.requery(); ,它不仅被贬低了。它也仅在数据库条目发生更改时才有效。
但现在,我想通过更改数据库中的设置来更改我的视图(在生日和日期之间切换),因此重新查询无法识别它。
对于所有更改都有效(有点脏): this.onCreate(null);
I used ListAdapter.notifyDataSetChanged(); this worked only on list (like ArrayList), when the listcontent changed.
Using databaseoutput, it doesn't work anymore. Therefore I took cursor.requery(); which is not only depricated. It also works only, if database entries changed.
But now, I want to change my view (switch between birthdays and dates) by changing my settings in a database, so requery does not recognize it.
For all changes works (a little bit dirty): this.onCreate(null);