dimanche 3 mai 2015

Delete item from listview and database

I'm trying to delete an item from a listview and from a sqlite database. There are several question on this site but I can't find a proper solution. My question is related with the design. I mean: the database access on Android should be done in async way to avoid to stop the main thread. My current listview, indeed, is loaded using an android Loader that it notified about any operation on the db and call onContentChanged(). The problem is how to proceed with the deletion: what is the best strategy? I see two ways:

  1. Delete from adapter, call notifyDataSetChanged() on it and then delete from db with an AsyncTask (or similar). The Loader will be notified. In this case there is maybe a refresh problem because the adapter is updated again due to loader update.
  2. Delete the item using an AsyncTask (or similar) and wait the update using the Loader. In this case the problem is that the UI is not updated when the user delete the item, but it's going to be deleted later (if no error occur) so it can be a bit weird from user point of view.

Aucun commentaire:

Enregistrer un commentaire