I am designing a drag and drop operation but I don't know how to access my data. Has anyone experience with Clip Data objects? Here is my code:
Starting the drag and drop:
ClipData dragData= ClipData.newPlainText("my", "test") );
v.startDrag(dragData,
new MyDragShadowBuilder(v),
v, 0);
Listening on the events:
case DragEvent.ACTION_DROP:{
if (event.getClipDescription().getLabel().equals("my"))
Log.d("myLog","Data:"+event.getClipData()+" "+event.getClipData().getItemCount());
not in every drag event can get the clip data, but some of them, such as ACTION_DROP type
dropableCanvas.setOnDragListener(new OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DROP:
ClipData clipData = event.getClipData();
//...
return true;
default:
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With