Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 28: Implementing Drag and Drop > Basics of Drag and Drop in 3.0+

Basics of Drag and Drop in 3.0+

Prior to Android 3.0, there was no direct support for drag and drop. You learned in the first section of this chapter how to drag a View around the screen; you also learned that it was possible to use the current location of the dragged object to determine if there was a drop target underneath. When the MotionEvent for the finger-up event was received, your code could figure out if that meant a drop had occurred. Although this was doable, it certainly wasn’t as easy as having direct support in Android for the drag-and-drop operation. You now have that direct support.

At its most basic, the drag-and-drop operation starts with a view declaring that a drag has started; then all interested parties watch the drag take place until the drop event is fired. If a view catches the drop event and wants to receive it, then a drag and drop has just occurred. If there is no view to receive the drop, or if the view that receives it doesn’t want it, then no drop takes place. Dragging is communicated through the use of a DragEvent object, which is passed to all of the drag listeners available.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial