问题
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