Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet203/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   199   200   201   202   203   204   205   206   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



256
CHAPTER 9: User Interface
} else {
theView.startDrag(dragData, shadow,
null, 0)
}
}
true
}
If the drag operation is not associated with a data type, you can just as well let dragData be 
null. In this case, you don’t have to build a ClipData object.
Listening to Drag Events
The complete set of events occurring during a drag-and-drop operation is governed by a 
drag-and-drop listener. Here’s an example:
class MyDragListener : View.OnDragListener {
override
fun onDrag(v: View, event: DragEvent): Boolean {
var res = true
when(event.action) {
DragEvent.ACTION_DRAG_STARTED -> {
when(v.tag) {
"DragSource" -> { res = false
/*not a drop receiver*/ }
"OneTarget" -> {
// could visibly change
// possible drop receivers
}
}
}
DragEvent.ACTION_DRAG_ENDED -> {
when(v.tag) {
"OneTarget" -> {
// could visibly change
// possible drop receivers
}
}
}
DragEvent.ACTION_DROP -> {
when(v.tag) {
"OneTarget" -> {
// visually revert drop
// receiver ...
}
}
Toast.makeText(v.context, "dropped!",
Toast.LENGTH_LONG).show()
}



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   199   200   201   202   203   204   205   206   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling