Sunday, 4 December 2016

Tutorial Swipe For Delete, Edit, Share Item on Android RecyclerView

Today i going to share you a tutorial using Ryclerview. This tutorial will show how to take an action by swapping the item on Recyclerview.
I using THIS LIBRARY for this tutorial. Take a look at the following steps.

PREPARATION


Compile this library to your build.gradle (Module :app) :

Prepare 2 layouts and give name like below :

  1. activity_main.xml
  2. swipe_layout.xml
Prepare 4 java class and give like below :
  1. MainActivity.java
  2. StudentModel.java
  3. DividetItemDecoration.java
  4. SwipeRecyclerViewAdapter.java

IMPLEMENTATION


1. Prepare all XML file that we'll use in this project

Create a divider layout in your Drawable folder, give name as divider.xml. Paste the code below :

Divider.xml used as the border line of recyclerview's item.


Modify your color.xml  or you can use the default color when the project created

Modify your style.xml, paste the code below :

Modify your activity_main.xml, paste the code below :

Modify your swipe_layout.xml, paste the code below :

2. Prepare all the Java class 

Modify your StudentModel.java like below :

After that, Modify your DividerItemDecoration.java until look like the following code :

Next, write down the following code in your SwipeRecyclerViewAdapter.java. Here the code :

Last, modify your MainActivity.java until similar like the following code :

That's all the steps for swiping on RecyclerView's item. Wait for other Tutorial.

BELOW IS THE COMPLETE PROJECT LINK : LINK GITHUB


EmoticonEmoticon