Reputation: 6531
I'm trying to use Android's new Drag&Drop framework and I run into the following issue:
I'm operating inside of one single Activity, so Class Sources are available.
Upvotes: 0
Views: 1525
Reputation: 421
You could try a number of things. In my app, this is how i did it:
public boolean onLongClick(View v)
{
dragged_view = v;
removeTransition(v);
ClipData data = ClipData.newPlainText("path", ((TextView)v.findViewById(R.id.file_name)).getText());
v.startDrag(data, new Shadow(v, c), v, 0);
return true;
}
I trigger the drag even on a long click gesture. I have a global View
variable named dragged_view
so that I can reference it on ACTION_DROP
.
Another thing I did is pass the View
as the local state object in the startDrag()
method (it's the 3rd argument). I can then get it via getLocalState()
and use it for reference, as in this code snippet:
item_drag_listener = new View.OnDragListener(){
public boolean onDrag(View v, DragEvent event){
if (event.getLocalState() == v)
return true;
overlays = v.findViewById(R.id.copy_move_overlays);
switch (event.getAction()){
case DragEvent.ACTION_DRAG_ENTERED:
overlays.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_EXITED:
overlays.setVisibility(View.INVISIBLE);
break;
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DROP:
return true;
}
return false;
}
};
Upvotes: 1
Reputation: 6531
I implemented dragging and dropping a view, by introducing a DragHandler class with a variable
View isDraggedNow;
This Variable allwasy contains a dragged view, so every class can easily take it on DragEvent.ACTION_DRAG_ENTERED
Upvotes: 0