How to update ListView in case of CursorAdapter usage?

后端 未结 6 845
北荒
北荒 2020-12-09 10:11

The reason I\'m asking that is because requery() is deprecated. What is the best way now to refresh your ListView?

6条回答
  •  失恋的感觉
    2020-12-09 10:46

    requery() updates a Cursor, not a CursorAdapter. As you say, it has been deprecated, and its replacement is:

    oldCursor = myCursorAdapter.swapCursor(newCursor); // hands you back oldCursor
    

    or:

    myCursorAdapter.changeCursor(newCursor); // automatically closes old Cursor
    

    myCursorAdapter.notifyDataSetChanged() notifies the ListView that the data set has changed, and it should refresh itself

提交回复
热议问题