views:

381

answers:

1

I have a database that gets updated by a background thread. Is is possible for the UI ouput(using a listview) to change when a database entry is added/deleted? I've seen examples of using SimpleCursorAdapter and listViewAdapters and I'm not sure which to use and if it would even work.

I found an "efficient" listViewAdapter which would work great for me since it doesn't call findViewById often and I can change the data structure to hold exactly what I need, but I don't know how to hook it into my database adapter so it dynamically updates the output when there is a database change. Example: http://www.androidsnippets.org/snippets/125/

Thanks for any advice.

+1  A: 

Use a SimpleCursorAdapter, and call requery() on the Cursor as needed. That will fetch the latest data and will update the associated ListView.

CommonsWare
Who would call requery()? If the user is already viewing the list onscreen and the background thread adds an entry, I wanted the list to be refreshed. Would my dbAdapter call it after it modifies the DB thus refreshing the currently displayed listview? I have the above linked example retrieving and displaying items from my DB, but I know it won't dynamically update my output while viewing the list. Stinks because I spent a little time modifying the code to work with my DB entries and now I'm not sure if I have to scrap all that work.
Jim D.
The background thread needs to alert the UI: "yo, dude, there's a data change, please requery()".
CommonsWare