Android-RecyclerView-Swipe-Gestures
Simple to use swipe gestures for an Android RecyclerView.
1. Introduction
An easy to use and highly customizable implemenation of swipe gestures for an android RecyclerView.
- Support for left and right swipes for any RecyclerView
- Set Colours as background for each swipe direction
- Set Icons for each swipe direction
- Set texts in addition to icons
2. Planned
- The Actions will be executed only when clicking on the coloured button, which will be schown when swiped, not directly after swiping.
- More then one Action for each swipe direction (several buttons will be displayed)
3. Setup
3.1. Add JitPack to your Project
Gradle:
- Add it in your root build.gradle at the end of repositories:
- Add the dependencie
Maven:
- Add the JitPack Repository to your pom.xml
- Add the dependencie to your pom.xml
Or find other versions here:
3.2 Import SwipeGestureManager
In your Activity add
4. Usage
4.1 Implement the SwipeCallbackLeft
and/or SwipeCallbackLeft
:
In your activity implement the interfaces.
Here you put the code which will be executed when the recyycler item was swiped.
4.2 Initialize 'SwipeGestureManager'in your activity :
If you just need one swipe gesture the just implement one of the interfaces and pass it:
4.3 Set a colour:
Use the setter to set a colour:
You can set a different colour for the two directions.
The standard colours are RED and GREEN.
Colours
Blue | Yellow |
---|---|
![]() |
![]() |
4.4 Set Icons:
Optionally you can use icons for the swipe acions which will be displayed when the swpie is performed.
That again works for both actions.
you also can change the size of the icons by using
Icon | Icon |
---|---|
![]() |
![]() |
Small | Small |
![]() |
![]() |
Big | Big |
![]() |
![]() |
4.5 Text
You can set a text (insead or with and icon), the text can be customized by using the
setters.
Customize the text :
Texts can also be customized seperatly by using the setters as follows:
Text | Text |
---|---|
Right Text | Small |
![]() |
![]() |
Text and icon color | Only Text |
![]() |
![]() |
4.6 Attach to the RechylerViewAdapter
You need to attach the swipe gestures to the RecyyclerView Adapter using a ItemTouchHelper
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(recyclerAdapterSwipeGestures);
itemTouchHelper.attachToRecyclerView(recyclerView);
And thats it for now.
You can find an example implementation in the MainActivity
GitHub
https://github.com/WilliBoelke/simple-recycler-view-swipe-gestures