public final class ItemDragHelper extends RecyclerViewItemHelper<ItemDragHelper.Interactor>
RecyclerViewItemHelper that may be used to support drag feature for items
displayed in a RecyclerView widget. Instance of this helper may be simply created via
ItemDragHelper() constructor.
In order to support drag feature for a desired adapter, such adapter must implement ItemDragHelper.DragAdapter
interface and needs to be attached to its corresponding RecyclerView before call to
RecyclerViewItemHelper.attachToRecyclerView(RecyclerView) which will attach such adapter to the drag helper
automatically. Also all ViewHolders of that adapter of which item
views are desired to be dragged, must implement ItemDragHelper.DragViewHolder interface as other view
holder implementations will be ignored by the ItemDragHelper API. When the ItemDragHelper.DragAdapter
is properly attached, the item helper will delegate to it all drag gesture related callbacks/events
whenever appropriate via the adapter's interface.
ItemDragHelper.OnDragListener may be registered for the helper's ItemDragHelper.Interactor via
ItemDragHelper.Interactor#addOnDragListener(OnDragListener) in order to receive callbacks
about started, finished or canceled drag gesture for a particular
ViewHolder. If the listener is no more needed it should be
unregistered via ItemDragHelper.Interactor#removeOnDragListener(OnDragListener).| Modifier and Type | Class and Description |
|---|---|
static interface |
ItemDragHelper.DragAdapter
Required interface for adapters which want to support drag feature for theirs
ViewHolders. |
static interface |
ItemDragHelper.DragViewHolder
Required interface for all
ViewHolders which want to support
drag feature for theirs corresponding item views. |
static class |
ItemDragHelper.Interactor
A
ItemInteractor implementation used by ItemDragHelper to handle drag gesture
related callbacks and to delegate drag events to the view holder that is being dragged and
also to it parent adapter in order to properly move dragged items in the adapter's data set. |
static interface |
ItemDragHelper.OnDragListener
Listener which may be used to receive callbacks about started, finished or
canceled drag gesture for a specific
RecyclerView.ViewHolder instance. |
RecyclerViewItemHelper.Direction, RecyclerViewItemHelper.Interaction, RecyclerViewItemHelper.InteractiveViewHolder, RecyclerViewItemHelper.ItemInteractor, RecyclerViewItemHelper.MovementItemTouchHelper.Callback, ItemTouchHelper.SimpleCallback, ItemTouchHelper.ViewDropHandler| Modifier and Type | Field and Description |
|---|---|
static int |
INTERACTION
Interaction constant specific for
ItemDragHelper. |
static float |
MOVE_THRESHOLD
Default move threshold for the drag gesture.
|
ACTION_STATE_DRAG, ACTION_STATE_IDLE, ACTION_STATE_SWIPE, ANIMATION_TYPE_DRAG, ANIMATION_TYPE_SWIPE_CANCEL, ANIMATION_TYPE_SWIPE_SUCCESS, DOWN, END, LEFT, RIGHT, START, UP| Constructor and Description |
|---|
ItemDragHelper()
Creates a new instance of ItemDragHelper.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
makeDragFlags(int movementFlags)
Makes movement flags for the drag gesture.
|
attachToRecyclerView, getInteractorgetItemOffsets, onChildViewAttachedToWindow, onChildViewDetachedFromWindow, onDraw, onDrawOver, startDrag, startSwipegetItemOffsets, onDraw, onDrawOverpublic static final int INTERACTION
ItemDragHelper.public static final float MOVE_THRESHOLD
public static int makeDragFlags(int movementFlags)
movementFlags - The desired movement flags. One of flags defined by
@Movement annotation.ItemDragHelper.Callback#makeMovementFlags(int, int)