开发者

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 Da开发者_运维技巧ta 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

Android Drag and Drop getClipData returns always null

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

Android Drag and Drop getClipData returns always null


Before you start your drag set some clip data using the following code

ClipData.Item item = new ClipData.Item((CharSequence) v.getTag());
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData dragData = new ClipData(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜