# OnDragInitiatedListener

Artifact: [androidx.recyclerview:recyclerview-selection](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/selection/OnDragInitiatedListener.java+class:androidx.recyclerview.selection.OnDragInitiatedListener) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public interface OnDragInitiatedListener
```

<br />

*** ** * ** ***

Register an OnDragInitiatedListener to be notified when user intent to perform drag and drop operations on an item or items has been detected. Handle these events using `https://developer.android.com/reference/android/view/View.html` support for Drag and drop.

See `https://developer.android.com/reference/android/view/View.html#startDragAndDrop(android.content.ClipData, android.view.View.DragShadowBuilder, java.lang.Object, int)` for details.

## Summary

| ### Public methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/recyclerview/selection/OnDragInitiatedListener#onDragInitiated(android.view.MotionEvent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/MotionEvent.html e)` Called when user intent to perform a drag and drop operation has been detected. |

## Public methods

### onDragInitiated

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
abstract boolean onDragInitiated(@NonNull MotionEvent e)
```

Called when user intent to perform a drag and drop operation has been detected.

The following circumstances are considered to be expressing drag and drop intent:

1. Long press on selected item.
2. Click and drag in the `https://developer.android.com/reference/androidx/recyclerview/selection/ItemDetailsLookup.ItemDetails#inDragRegion(android.view.MotionEvent)` of selected item with a pointer device.
3. Click and drag in drag region of un-selected item with a pointer device.

The RecyclerView item at the coordinates of the MotionEvent is not supplied as a parameter to this method as there may be multiple items selected or no items selected (as may be the case in pointer drive drag and drop.)

Obtain the current list of selected items from `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker#copySelection(androidx.recyclerview.selection.MutableSelection<K>)`. If there is no selection get the item under the event using `https://developer.android.com/reference/androidx/recyclerview/selection/ItemDetailsLookup#getItemDetails(android.view.MotionEvent)`.

Drag region used with pointer devices is specified by `https://developer.android.com/reference/androidx/recyclerview/selection/ItemDetailsLookup.ItemDetails#inDragRegion(android.view.MotionEvent)`

See `https://developer.android.com/reference/android/view/View.html#startDragAndDrop(android.content.ClipData, android.view.View.DragShadowBuilder, java.lang.Object, int)` for details on drag and drop implementation.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/MotionEvent.html e` | the event associated with the drag. |

| Returns |
|---|---|
| `boolean` | true if drag and drop was initiated. |