SimpleCallback

abstract class SimpleCallback : ItemTouchHelper.Callback
kotlin.Any
   ↳ androidx.recyclerview.widget.ItemTouchHelper.Callback
   ↳ androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback

A simple wrapper to the default Callback which you can construct with drag and swipe directions and this class will handle the flag callbacks. You should still override onMove or onSwiped depending on your use case.

ItemTouchHelper mIth = new ItemTouchHelper(
          new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
              ItemTouchHelper.LEFT) {
              public boolean onMove(RecyclerView recyclerView,
                  ViewHolder viewHolder, ViewHolder target) {
                  final int fromPos = viewHolder.getAdapterPosition();
                  final int toPos = target.getAdapterPosition();
                  // move item in `fromPos` to `toPos` in adapter.
                  return true;// true if moved, false otherwise
              }
              public void onSwiped(ViewHolder viewHolder, int direction) {
                  // remove from adapter
              }
      });
      

Summary

Inherited constants

Public constructors

<init>(dragDirs: Int, swipeDirs: Int)

Creates a Callback for the given drag and swipe allowance.

Public methods

open Int
getDragDirs(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder)

Returns the drag directions for the provided ViewHolder.

open Int
getMovementFlags(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder)

open Int
getSwipeDirs(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder)

Returns the swipe directions for the provided ViewHolder.

open Unit
setDefaultDragDirs(defaultDragDirs: Int)

Updates the default drag directions.

open Unit
setDefaultSwipeDirs(defaultSwipeDirs: Int)

Updates the default swipe directions.

Inherited functions

Public constructors

<init>

SimpleCallback(dragDirs: Int, swipeDirs: Int)

Creates a Callback for the given drag and swipe allowance. These values serve as defaults and if you want to customize behavior per ViewHolder, you can override getSwipeDirs(RecyclerView, ViewHolder) and / or getDragDirs(RecyclerView, ViewHolder).

Parameters
dragDirs Int: Binary OR of direction flags in which the Views can be dragged. Must be composed of LEFT, RIGHT, START, , UP and DOWN.
swipeDirs Int: Binary OR of direction flags in which the Views can be swiped. Must be composed of LEFT, RIGHT, START, , UP and DOWN.

Public methods

getDragDirs

open fun getDragDirs(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder): Int

Returns the drag directions for the provided ViewHolder. Default implementation returns the drag directions that was set via constructor or setDefaultDragDirs(int).

Parameters
recyclerView RecyclerView: The RecyclerView to which the ItemTouchHelper is attached to.
viewHolder RecyclerView: The ViewHolder for which the swipe direction is queried.
Return
Int: A binary OR of direction flags.

getMovementFlags

open fun getMovementFlags(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder): Int

getSwipeDirs

open fun getSwipeDirs(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder): Int

Returns the swipe directions for the provided ViewHolder. Default implementation returns the swipe directions that was set via constructor or setDefaultSwipeDirs(int).

Parameters
recyclerView RecyclerView: The RecyclerView to which the ItemTouchHelper is attached to.
viewHolder RecyclerView: The ViewHolder for which the swipe direction is queried.
Return
Int: A binary OR of direction flags.

setDefaultDragDirs

open fun setDefaultDragDirs(defaultDragDirs: Int): Unit

Updates the default drag directions. For example, you can use this method to toggle certain directions depending on your use case.

Parameters
defaultDragDirs Int: Binary OR of directions in which the ViewHolders can be dragged.

setDefaultSwipeDirs

open fun setDefaultSwipeDirs(defaultSwipeDirs: Int): Unit

Updates the default swipe directions. For example, you can use this method to toggle certain directions depending on your use case.

Parameters
defaultSwipeDirs Int: Binary OR of directions in which the ViewHolders can be swiped.