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.
For example, if you would like to let your user to be able to drag an Item by touching one of its descendants, you may implement it as follows:
    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;
        }
    });

Parameters

viewHolder

The ViewHolder to start dragging. It must be a direct child of RecyclerView.

See also