Need help with SwipeableRecyclerView?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

brnunes
186 Stars 43 Forks Apache License 2.0 38 Commits 0 Opened issues

Description

Implementation of an Android CardView list in a RecyclerView that allows dismissing/deleting elements by swiping them to the left or right.

Services available

!
?

Need anything else?

Contributors list

# 291,626
Objecti...
Swift
uitextf...
hashtag...
19 commits
# 216,325
PHP
mesh
mesh-ne...
IPFS
7 commits
# 467,513
Java
Shell
Android
2 commits
# 1,844
image-f...
assembl...
netfram...
residua...
1 commit

Android SwipeableRecyclerView

Based on romannurik`s Android-SwipeToDismiss.

Sample project implementation of a single column list of

CardView
s in a
RecyclerView
with a
TouchListener
that allows dismissing of elements by swiping the elements to the left or right.

Output sample

How to use

  • Add these Gradle dependencies to your app's module:

    dependencies {
        ...
    
    
    // already includes 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.github.brnunes:swipeablerecyclerview:1.0.2'
    
    // only necessary if you are using CardView
    compile 'com.android.support:cardview-v7:23.1.1'

    }

    The

    RecyclerView
    and
    CardView
    widgets are part of the v7 Support Libraries.
  • Instantiate a

    SwipeableRecyclerViewTouchListener
    passing as parameters the
    RecyclerView
    and a
    SwipeableRecyclerViewTouchListener.SwipeListener
    that will receive the callbacks.
  • Add the instantiated

    SwipeableRecyclerViewTouchListener
    as a
    RecyclerView.OnItemTouchListener
    .
    SwipeableRecyclerViewTouchListener swipeTouchListener =
            new SwipeableRecyclerViewTouchListener(mRecyclerView,
                    new SwipeableRecyclerViewTouchListener.SwipeListener() {
                        @Override
                        public boolean canSwipeLeft(int position) {
                            return true;
                        }
    
    
                    @Override
                    public boolean canSwipeRight(int position) {
                        return true;
                    }
    
                    @Override
                    public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] reverseSortedPositions) {
                        for (int position : reverseSortedPositions) {
                            mItems.remove(position);
                            mAdapter.notifyItemRemoved(position);
                        }
                        mAdapter.notifyDataSetChanged();
                    }
    
                    @Override
                    public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] reverseSortedPositions) {
                        for (int position : reverseSortedPositions) {
                            mItems.remove(position);
                            mAdapter.notifyItemRemoved(position);
                        }
                        mAdapter.notifyDataSetChanged();
                    }
                });

    mRecyclerView.addOnItemTouchListener(swipeTouchListener);

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.