Swipe to delete RecyclerView Item
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.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 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.
Click Here To Download Full Code
Comments
Post a Comment