Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update ListView in case of CursorAdapter usage?

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

like image 864
Eugene Avatar asked Aug 11 '11 13:08

Eugene


People also ask

How can you update a ListView dynamically?

This example demonstrates how do I dynamically update a ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you refresh a ListView?

Example – Refresh Android ListView On clicking Change button, we are changing the data in the string array. On clicking the Refresh ListView button, we are calling the method notifyDataSetChanged() on the Adapter.


1 Answers

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

like image 174
Pikaling Avatar answered Sep 19 '22 16:09

Pikaling