startDrag
Starts dragging the provided ViewHolder. By default, ItemTouchHelper starts a drag when a View is long pressed. You can disable that behavior by overriding isLongPressDragEnabled.
For this method to work:
- The provided ViewHolder must be a child of the RecyclerView to which this ItemTouchHelper is attached.
- ItemTouchHelper.Callback must have dragging enabled.
- There must be a previous touch event that was reported to the ItemTouchHelper through RecyclerView's ItemTouchListener mechanism. As long as no other ItemTouchListener grabs previous events, this should work as expected.
viewHolder.dragButton.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mItemTouchHelper.startDrag(viewHolder);
}
return false;
}
});
Content copied to clipboard
Parameters
viewHolder
The ViewHolder to start dragging. It must be a direct child of RecyclerView.