A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.
- Add these lines to your
build.gradle
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.CodeFalling:RecyclerViewSwipeDismiss:v1.1.1'
}
- Build
onTouchListener
and bind it to yourRecyclerView
SwipeDismissRecyclerViewTouchListener listener = new SwipeDismissRecyclerViewTouchListener.Builder(
recyclerView,
new SwipeDismissRecyclerViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(View view) {
// Do what you want when dismiss
}
})
.setIsVertical(false)
.setItemTouchCallback(
new SwipeDismissRecyclerViewTouchListener.OnItemTouchCallBack() {
@Override
public void onTouch(int index) {
// Do what you want when item be touched
}
})
.create();
recyclerView.setOnTouchListener(listener);
-
setIsVertical(false)
means allow swipe in horizontal direction -
listener.setEnabled(false)
can disable swipe to dismiss -
onTouch
will be called when MOUSE_UP on item without swipe
You can see sample code in sample/MainActivity.java