Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage undo after swipe to delete in android ListView?

I need to implement swipe to delete in a ListView with Undo function as in Gmail App

I know that there are questions already asking about swipe to delete like

Remove item listview with Slide - Like Gmail

and

android swipe to delete list row

But none of them explains how to manage Undo after deletion and Animate back the deleted view on undo!

I found other one with no Answer here

How to implement gmail like Achieve or Undo action in a list item

So here is my question.

How to create a listview in android with swipe to delete then show UNDO in the deleted space and Animate back the same view if the undo is pressed, also remove the undo option on scroll or other item click or swipe?

You smart people have any idea?

| ----------- ITEM 1-----------|

| ----------- ITEM 2-----------|

| --Deleted-------<[UNDO]>|

| ----------- ITEM 4-----------|

| ----------- ITEM 5-----------|

note: sorry that I cant add an image because of my low reputation!

like image 693
user2364935 Avatar asked Aug 30 '13 06:08

user2364935


People also ask

How to swipe to delete RecyclerView?

Android Swipe To Delete. Swipe to delete feature is commonly used to delete rows from a RecyclerView. In order to implement Swipe to delete feature, we need to use the ItemTouchHelper utility class.


2 Answers

You can find exactly what you asked for at https://github.com/nhaarman/ListViewAnimations

like image 122
user2760845 Avatar answered Oct 13 '22 22:10

user2760845


Your question sounds like you're confused about how to manage the actual undo part. If that is the case then I would suggest you look into the design pattern called 'Command Design Pattern'. You can queue up 'Commands' like delete, then only commit them once the undo timer or however you implement it is finished.

like image 42
Nick H Avatar answered Oct 14 '22 00:10

Nick H