Slide 64
Slide 64 text
// Use the DragStartHelper class to easily support initiating drag and drop in response to
// both long press and mouse drag events. Note the call to attach() at the end. Without it,
// the listener would never actually be attached to the view. Also note that attach() replaces
// any OnTouchListener or OnLongClickListener already attached to the view.
DragStartHelper(binding.textDragItem) { view, _ ->
val text = (view as TextView).text
// Create the ClipData to be shared
val dragClipData = ClipData.newPlainText(/*label*/"Text", text)
// Use the default drag shadow
val dragShadowBuilder = View.DragShadowBuilder(view)
// Initiate the drag. Note the DRAG_FLAG_GLOBAL, which allows for drag events to be istened
// to by apps other than the source app.
view.startDragAndDrop(dragClipData, dragShadowBuilder, null, DRAG_FLAG_GLOBAL)
}.attach()
https://github.com/android/user-interface-samples/tree/main/DragAndDrop