Pro Android with Kotlin


CHAPTER 9: User Interface



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə211/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   207   208   209   210   211   212   213   214   ...   231
@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()
}



Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   207   208   209   210   211   212   213   214   ...   231




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə