I'm trying to implement swipe to delete and in a ListView
using the SwipeToDismissUndoList library which extends Roman Nurik's SwipeToDismiss sample.
My issue is in the delete animation. Since the ListView
is backed by a CursorAdapter
, the animation triggers the onDismiss
callback in onAnimationEnd
but this means that the animation has run and reset itself before the CursorAdapter
updates with the delete.
This ends up looking like a flicker to the user where they delete a note by swiping it away, then the view is back for a split second and then disappears because the CursorAdapter
has picked up the data change.
Here is my OnDismissCallback
:
private SwipeDismissList.OnDismissCallback dismissCallback =
new SwipeDismissList.OnDismissCallback() {
@Override
public SwipeDismissList.Undoable onDismiss(ListView listView, final int position) {
Cursor c = mAdapter.getCursor();
c.moveToPosition(position);
final int id = c.getInt(Query._ID);
final Item item = Item.findById(getActivity(), id);
if (Log.LOGV) Log.v("Deleting item: " + item);
final ContentResolver cr = getActivity().getContentResolver();
cr.delete(Items.buildItemUri(id), null, null);
mAdapter.notifyDataSetChanged();
return new SwipeDismissList.Undoable() {
public void undo() {
if (Log.LOGV) Log.v("Restoring Item: " + item);
ContentValues cv = new ContentValues();
cv.put(Items._ID, item.getId());
cv.put(Items.ITEM_CONTENT, item.getContent());
cr.insert(Items.CONTENT_URI, cv);
}
};
}
};
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