Android how do you code now if requery is deprecated?

泄露秘密 提交于 2019-12-10 03:54:15

问题


as per the topic. 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?


回答1:


again re-initialize cursor when your any DML query execute, can refer this




回答2:


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

{
    Cursor c =//Populating cursor again
    while (c.moveToNext()) {
    }
    if (c != null) c.close();
}



回答3:


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.




回答4:


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);



来源:https://stackoverflow.com/questions/7157023/android-how-do-you-code-now-if-requery-is-deprecated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!