Loading...

Android Drag Select RecyclerView Library

TouchListener that can be attached to any RecyclerView and handles multi selection for you. It's a simple one class TouchListener that can be attached to any RecyclerView and handles multi selection in google photos style via long pressing on an item and moving the finger up/down to select more items (it even scrolls if you reach the edges of the RecyclerView)


Related:


Library Details:


Name: DragSelectRecyclerView 
Owner: MFlisar
Source: Download Full Library Source Code From GitHub

Gradle (via JitPack.io)


1. Add jitpack to your project's build.gradle:

repositories {
    maven { url "https://jitpack.io" }
}

2. Add the compile statement to your module's build.gradle:

dependencies {
    compile 'com.github.MFlisar:DragSelectRecyclerView:0.2'
}

Usage

Create the a touch listener like following

mDragSelectTouchListener = new DragSelectTouchListener()
    .withSelectListener(new DragSelectTouchListener.OnDragSelectListener() {
        @Override
        public void onSelectChange(int start, int end, boolean isSelected) {
            // update your selection
            // range is inclusive start/end positions
        }
    })

Following is all optional

    .withMaxScrollDistance(distance)    // default: 16;     defines the speed of the auto scrolling

    .withTopOffset(toolbarHeight)       // default: 0;      set an offset for the touch region on top of the RecyclerView

    .withBottomOffset(toolbarHeight)    // default: 0;      set an offset for the touch region on bottom of the RecyclerView

    .withScrollAboveTopRegion(enabled)  // default: true;   enable auto scrolling, even if the finger is moved above the top region

    .withScrollBelowTopRegion(enabled)  // default: true;   enable auto scrolling, even if the finger is moved below the top region

    .withDebug(enabled);                // default: false;
attach it to the RecyclerView

recyclerView.addOnItemTouchListener(mDragSelectTouchListener);

On item long press, inform the listener so that it can start doing it's magic

// if one item is long pressed, we start the drag selection like following:
// we just call this function and pass in the position of the first selected item
mDragSelectTouchListener.startDragSelection(position);

TODO

support horizontal RecyclerViews... should be quite simple, but is not yet implemented
RecyclerView 6080350712298345272
Home item