Swipe to delete RecyclerView Item


"Swipe To Delete RecyclerView" 

 In previous blog we have studied how to implement RecyclerView in android. Now we are going to studying about touch events in RecyclerView. In this blog I'm going to write about how to delete row from RecyclerView by swipe from left to right or vice versa.

For implementing touch event in RecyclerView we need to attach ItemTouchHelper. See the following code snippet.


First create removeItem() method as shown in following code and paste it in "RecyclerAdapter.java" class, created in previous example.



Now copy and paste the code after setting adapter to recyclerview as shown in previous demo of RecyclerView.



Now attach ItemTouchHelper to RecyclerView as shown below.




Done. Now run your code and swipe on row left side or right side , and see the result. The row will be remove from your RecyclerView.

Enjoy coding!😊
Click Here To Download Full Code

Comments

Popular posts from this blog

SQLite with RecyclerView

Update data in SQLite