public abstract static class ItemTouchHelper.SimpleCallback extends ItemTouchHelper.Callback
ItemTouchHelper mIth = new ItemTouchHelper( new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT) { public abstract boolean onMove(RecyclerView recyclerView, RowViewHolder viewHolder, RowViewHolder target) { final int fromPos = viewHolder.getAdapterPosition(); final int toPos = viewHolder.getAdapterPosition(); // move item in `fromPos` to `toPos` in adapter. return true;// true if moved, false otherwise } public void onSwiped(RowViewHolder viewHolder, int direction) { // remove from adapter } });
DEFAULT_DRAG_ANIMATION_DURATION, DEFAULT_SWIPE_ANIMATION_DURATION
Constructor and Description |
---|
SimpleCallback(int dragDirs,
int swipeDirs)
Creates a Callback for the given drag and swipe allowance.
|
Modifier and Type | Method and Description |
---|---|
int |
getDragDirs(android.support.v7.widget.RecyclerView recyclerView,
android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
Returns the drag directions for the provided RowViewHolder.
|
int |
getMovementFlags(android.support.v7.widget.RecyclerView recyclerView,
android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
Should return a composite flag which defines the enabled move directions in each state
(idle, swiping, dragging).
|
int |
getSwipeDirs(android.support.v7.widget.RecyclerView recyclerView,
android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
Returns the swipe directions for the provided RowViewHolder.
|
void |
setDefaultDragDirs(int defaultDragDirs)
Updates the default drag directions.
|
void |
setDefaultSwipeDirs(int defaultSwipeDirs)
Updates the default swipe directions.
|
canDropOver, chooseDropTarget, clearView, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getMoveThreshold, getSwipeEscapeVelocity, getSwipeThreshold, getSwipeVelocityThreshold, interpolateOutOfBoundsScroll, isItemViewSwipeEnabled, isLongPressDragEnabled, makeFlag, makeMovementFlags, onChildDraw, onChildDrawOver, onMove, onMoved, onSelectedChanged, onSwiped
public SimpleCallback(int dragDirs, int swipeDirs)
#getSwipeDirs(RecyclerView, ViewHolder)
and / or #getDragDirs(RecyclerView, ViewHolder)
.dragDirs
- Binary OR of direction flags in which the Views can be dragged. Must be
composed of ItemTouchHelper.LEFT
, ItemTouchHelper.RIGHT
, ItemTouchHelper.START
, ItemTouchHelper.END
,
ItemTouchHelper.UP
and ItemTouchHelper.DOWN
.swipeDirs
- Binary OR of direction flags in which the Views can be swiped. Must be
composed of ItemTouchHelper.LEFT
, ItemTouchHelper.RIGHT
, ItemTouchHelper.START
, ItemTouchHelper.END
,
ItemTouchHelper.UP
and ItemTouchHelper.DOWN
.public void setDefaultSwipeDirs(int defaultSwipeDirs)
defaultSwipeDirs
- Binary OR of directions in which the ViewHolders can be swiped.public void setDefaultDragDirs(int defaultDragDirs)
defaultDragDirs
- Binary OR of directions in which the ViewHolders can be dragged.public int getSwipeDirs(android.support.v7.widget.RecyclerView recyclerView, android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
setDefaultSwipeDirs(int)
.recyclerView
- The RecyclerView to which the ItemTouchHelper is attached to.viewHolder
- The RecyclerView for which the swipe drection is queried.public int getDragDirs(android.support.v7.widget.RecyclerView recyclerView, android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
setDefaultDragDirs(int)
.recyclerView
- The RecyclerView to which the ItemTouchHelper is attached to.viewHolder
- The RecyclerView for which the swipe drection is queried.public int getMovementFlags(android.support.v7.widget.RecyclerView recyclerView, android.support.v7.widget.RecyclerView.ViewHolder viewHolder)
ItemTouchHelper.Callback
ItemTouchHelper.Callback.makeMovementFlags(int,
int)
or ItemTouchHelper.Callback.makeFlag(int, int)
.
This flag is composed of 3 sets of 8 bits, where first 8 bits are for IDLE state, next
8 bits are for SWIPE state and third 8 bits are for DRAG state.
Each 8 bit sections can be constructed by simply OR'ing direction flags defined in
ItemTouchHelper
.
For example, if you want it to allow swiping LEFT and RIGHT but only allow starting to
swipe by swiping RIGHT, you can return:
makeFlag(ACTION_STATE_IDLE, RIGHT) | makeFlag(ACTION_STATE_SWIPE, LEFT | RIGHT);This means, allow right movement while IDLE and allow right and left movement while swiping.
getMovementFlags
in class ItemTouchHelper.Callback
recyclerView
- The RecyclerView to which ItemTouchHelper is attached.viewHolder
- The RowViewHolder for which the movement information is necessary.ItemTouchHelper.Callback.makeMovementFlags(int, int)
,
ItemTouchHelper.Callback.makeFlag(int, int)