Search code examples
androiddatabaselistviewadaptersimplecursoradapter

ListView SimpleCursorAdapter Update


I have a ListActivity with a SimpleCursorAdapter, thus the list view contains data from a database. If I am looking at the list I want it to update (re-query) itself when new data is put in the database being used by the SimpleCursorAdapter. Is the best way to do this to set a content observer on the database and call a requery() on the cursor when new content comes in ?


Solution

  • Is the best way to do this to set a content observer on the database and call a requery() on the cursor when new content comes in?

    Yes, when there are changes in the database ContentObserver, you should refresh the cursor by calling requery(). Now this method is deprecated though, just request a new cursor, so you can do this asynchronously and update your list view once the new cursor arrived.