The reason I'm asking that is because requery()
is deprecated. What is the best way now to refresh your ListView
?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With