# OnDragInitiatedListener

# 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)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/recyclerview/selection/OnDragInitiatedListener "View this page in Java")


```
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 [View](https://developer.android.com/reference/android/view/View.html) support for Drag and drop.

See [startDragAndDrop](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 functions                                 |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [onDragInitiated](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/OnDragInitiatedListener#onDragInitiated(android.view.MotionEvent))`(e: `[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html)`)` Called when user intent to perform a drag and drop operation has been detected. |

## Public functions

### onDragInitiated

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

```
fun onDragInitiated(e: MotionEvent): Boolean
```

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 [drag region](https://developer.android.com/reference/kotlin/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 [copySelection](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/SelectionTracker#copySelection(androidx.recyclerview.selection.MutableSelection<K>)). If there is no selection get the item under the event using [getItemDetails](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/ItemDetailsLookup#getItemDetails(android.view.MotionEvent)).

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

See [startDragAndDrop](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                                         |
|-------------------------------------------------------------------------------------------|-------------------------------------|
| `e: `[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html) | the event associated with the drag. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if drag and drop was initiated. |