I have a ListView backed by a custom adapter based on a CursorAdapter.
The cursor I give it is based on a list of Notes in the database (each note is a DB row).
Everything works just fine until I delete a note from the database. I'm not sure how to properly update the cursor/adapter/listview to display the new data.
I've read conflicting posts on using adapter.notifyDataSetChanged()
vs cursor.requery()
to refresh the UI, but neither of them seems to work in this case. The only way I've been able to refresh it is by creating a new cursor from a new query and calling adapter.changeCursor(newCursor)
.
Could someone demonstrate the proper way to update the backing data and then the UI (with psuedocode if possible).
You have to requery
and then notifyDataSetChanged
.
Calling requery will re-execute the exact query that was used to create the cursor - that is, it won't re-execute the actual method in your code. So if your method contains dynamic stuff such as sorting based on a preference, it won't be updated. In this case, you don't want to use the same query, you want a different one.
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