Viktor Yakunin Viktor Yakunin -5 years ago 370
Android Question

Swipe to Dismiss for RecyclerView

I used to SwipeToDismiss library but now I'm trying to migrate to RecyclerView and things are not so obvious, do you know any replacements for this lib? Any ideas how to implement it from the scratch?

Answer Source

As of v22.2.0, the Android support team has included an ItemTouchHelper class that makes swipe-to-dismiss and drag-and-drop pretty simple. This may not be as full-featured as some of the libraries out there, but it comes directly from the Android team.

  • Update your build.gradle to import v22.2.+ of the RecyclerView library

    compile ''
  • Instantiate an ItemTouchHelper with an appropriate SimpleCallback

    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            //Remove swiped item from list and notify the RecyclerView
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);

    ** Note that the SimpleCallback takes in the directions that you want to enable drag-and-drop and the directions that you want to enable swiping.

  • Attach to your RecyclerView

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download