# DropHelper

# DropHelper

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

*** ** * ** ***

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

<br />

```
class DropHelper
```

<br />

*** ** * ** ***

Helper class used to configure[View](https://developer.android.com/reference/android/view/View.html)s to receive data dropped by a drag and drop operation. Includes support for content insertion using an[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener). Adds highlighting during the drag interaction to indicate to the user where the drop action can successfully take place.

To ensure that drop target highlighting and text data handling work correctly, all[EditText](https://developer.android.com/reference/android/widget/EditText.html)elements in the drop target view's descendant tree (that is, any`EditText`elements contained within the drop target) must be provided as arguments to a call to[addInnerEditTexts](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options.Builder#addInnerEditTexts(android.widget.EditText...)). Otherwise, an`EditText`within the target will steal the focus during the drag and drop operation, possibly causing undesired highlighting behavior.

Also, if the user is dragging text data and URI data in the drag and drop[ClipData](https://developer.android.com/reference/android/content/ClipData.html), one of the`EditText`elements in the drop target is automatically chosen to handle the text data. See[addInnerEditTexts](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options.Builder#addInnerEditTexts(android.widget.EditText...))for the order of precedence in selecting the`EditText`that handles the text data.

This helper attaches an[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener)to drop targets and configures drop targets to listen for drag and drop events (see[configureView](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper#configureView(android.app.Activity,android.view.View,java.lang.String[],androidx.core.view.OnReceiveContentListener))). Do not attach an[OnDragListener](https://developer.android.com/reference/android/view/View.OnDragListener.html)or additional`OnReceiveContentLister`to drop targets when using[DropHelper](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper).

**Note:**This class requires Android API level 24 or higher.  

|                                                 See also                                                  |
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| [Drag and drop](https://developer.android.com/guide/topics/ui/drag-drop)                                  | [Drag and drop](https://developer.android.com/guide/topics/ui/drag-drop)                                  |
| [Multi-window support](https://developer.android.com/guide/topics/large-screens/multi-window-support#dnd) | [Multi-window support](https://developer.android.com/guide/topics/large-screens/multi-window-support#dnd) |

## Summary

|                                                                                                                                   ### Nested types                                                                                                                                   |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[DropHelper.Options](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options) Options for configuring drop targets specified by[DropHelper](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper).                  |
| `class `[DropHelper.Options.Builder](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options.Builder) Builder for constructing a[DropHelper.Options](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options)instance. |

|                                    ### Public functions                                     |
|---------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [configureView](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper#configureView(android.app.Activity,android.view.View,java.lang.String[],androidx.core.view.OnReceiveContentListener))`(` ` activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html)`,` ` dropTarget: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` mimeTypes: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>,` ` onReceiveContentListener: `[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener) `)` Configures a`View`for drag and drop operations, including the highlighting that indicates the view is a drop target.                                                                                                                                                                     |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [configureView](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper#configureView(android.app.Activity,android.view.View,java.lang.String[],androidx.draganddrop.DropHelper.Options,androidx.core.view.OnReceiveContentListener))`(` ` activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html)`,` ` dropTarget: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` mimeTypes: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>,` ` options: `[DropHelper.Options](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options)`,` ` onReceiveContentListener: `[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener) `)` Configures a`View`for drag and drop operations, including the highlighting that indicates the view is a drop target. |

## Public functions

### configureView

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

```
java-static fun configureView(
    activity: Activity,
    dropTarget: View,
    mimeTypes: Array<String!>,
    onReceiveContentListener: OnReceiveContentListener
): Unit
```

Configures a`View`for drag and drop operations, including the highlighting that indicates the view is a drop target. Sets a listener that enables the view to handle dropped data.

Same as[configureView](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper#configureView(android.app.Activity,android.view.View,java.lang.String[],androidx.draganddrop.DropHelper.Options,androidx.core.view.OnReceiveContentListener))but with default configuration options.

**Note:** If the drop target contains[EditText](https://developer.android.com/reference/android/widget/EditText.html)elements, you must use[configureView](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper#configureView(android.app.Activity,android.view.View,java.lang.String[],androidx.draganddrop.DropHelper.Options,androidx.core.view.OnReceiveContentListener)). The`Options`argument enables you to specify a list of the`EditText`elements (see[addInnerEditTexts](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options.Builder#addInnerEditTexts(android.widget.EditText...))).  

|                                                                                      Parameters                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| `activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html)                                                                                            | The current`Activity`(used for URI permissions).                 |
| `dropTarget: `[View](https://developer.android.com/reference/android/view/View.html)                                                                                                 | A`View`that accepts the drag and drop data.                      |
| `mimeTypes: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>` | The MIME types the drop target can accept from the dropped data. |
| `onReceiveContentListener: `[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener)                                   | A listener that handles the dropped data.                        |

### configureView

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

```
java-static fun configureView(
    activity: Activity,
    dropTarget: View,
    mimeTypes: Array<String!>,
    options: DropHelper.Options,
    onReceiveContentListener: OnReceiveContentListener
): Unit
```

Configures a`View`for drag and drop operations, including the highlighting that indicates the view is a drop target. Sets a listener that enables the view to handle dropped data.

If the drop target's view hierarchy contains any`EditText`elements, they all must be specified in`options`(see[addInnerEditTexts](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options.Builder#addInnerEditTexts(android.widget.EditText...))).

View highlighting occurs for a drag action only if a MIME type in the[ClipDescription](https://developer.android.com/reference/android/content/ClipDescription.html)matches a MIME type provided in`mimeTypes`; wildcards are allowed (for example, "image/\*"). A drop can be executed and passed on to the`OnReceiveContentListener`even if the MIME type is not matched.

See[DropHelper](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper)for more information.  

|                                                                                      Parameters                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `activity: `[Activity](https://developer.android.com/reference/android/app/Activity.html)                                                                                            | The current`Activity`(used for URI permissions).                                                                                                             |
| `dropTarget: `[View](https://developer.android.com/reference/android/view/View.html)                                                                                                 | A`View`that accepts the drag and drop data.                                                                                                                  |
| `mimeTypes: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>` | The MIME types the drop target can accept from the dropped data.                                                                                             |
| `options: `[DropHelper.Options](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options)                                                              | Configuration options for the drop target (see[DropHelper.Options](https://developer.android.com/reference/kotlin/androidx/draganddrop/DropHelper.Options)). |
| `onReceiveContentListener: `[OnReceiveContentListener](https://developer.android.com/reference/kotlin/androidx/core/view/OnReceiveContentListener)                                   | A listener that handles the dropped data.                                                                                                                    |