java.lang.Object | ||
↳ | android.support.v7.widget.helper.ItemTouchHelper.Callback | |
↳ | android.support.v7.widget.helper.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 abstract boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder 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(ViewHolder viewHolder, int direction) { // remove from adapter } });
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.support.v7.widget.helper.ItemTouchHelper.Callback
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a Callback for the given drag and swipe allowance.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the drag directions for the provided ViewHolder.
| |||||||||||
Should return a composite flag which defines the enabled move directions in each state
(idle, swiping, dragging).
| |||||||||||
Returns the swipe directions for the provided ViewHolder.
| |||||||||||
Updates the default drag directions.
| |||||||||||
Updates the default swipe directions.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.support.v7.widget.helper.ItemTouchHelper.Callback
| |||||||||||
From class
java.lang.Object
|
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)
.
Returns the drag directions for the provided ViewHolder.
Default implementation returns the drag directions that was set via constructor or
setDefaultDragDirs(int)
.
recyclerView | The RecyclerView to which the ItemTouchHelper is attached to. |
---|---|
viewHolder | The RecyclerView for which the swipe drection is queried. |
Should return a composite flag which defines the enabled move directions in each state (idle, swiping, dragging).
Instead of composing this flag manually, you can use makeMovementFlags(int, int)
or 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.
recyclerView | The RecyclerView to which ItemTouchHelper is attached. |
---|---|
viewHolder | The ViewHolder for which the movement information is necessary. |
Returns the swipe directions for the provided ViewHolder.
Default implementation returns the swipe directions that was set via constructor or
setDefaultSwipeDirs(int)
.
recyclerView | The RecyclerView to which the ItemTouchHelper is attached to. |
---|---|
viewHolder | The RecyclerView for which the swipe drection is queried. |
Updates the default drag directions. For example, you can use this method to toggle certain directions depending on your use case.
defaultDragDirs | Binary OR of directions in which the ViewHolders can be dragged. |
---|
Updates the default swipe directions. For example, you can use this method to toggle certain directions depending on your use case.
defaultSwipeDirs | Binary OR of directions in which the ViewHolders can be swiped. |
---|