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
Solution 1:
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:
                returntrue;
            case DragEvent.ACTION_DROP:
                ClipData clipData = event.getClipData();
                //...returntrue;
            default:
                returnfalse;
            }
        }

Solution 2:
Before you start your drag set some clip data using the following code
ClipData.Itemitem=newClipData.Item((CharSequence) v.getTag());
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipDatadragData=newClipData(v.getTag().toString(), mimeTypes, item);
And then after you start dragging with v.startDrag(......); in the event DragEvent.ACTION_DROP you have to catch the clip data using the following code
String clipData = event.getClipDescription().getLabel().toString()
Once you have the clipData you can play around. This didn't return me null, check you at your end.
Post a Comment for "Android Drag And Drop Getclipdata Returns Always Null"