Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Drag and Drop getClipData returns always null

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());
like image 365
Anthea Avatar asked May 30 '11 10:05

Anthea


1 Answers

not in every drag event can get the clip data, but some of them, such as ACTION_DROP type

enter image description here

    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;
            }
        }

enter image description here

like image 54
sam sha Avatar answered Oct 26 '22 22:10

sam sha