Skip to content

Instantly share code, notes, and snippets.

@IvBaranov
Last active October 20, 2017 08:09
Show Gist options
  • Save IvBaranov/02cccc6e2dc4f71e74015740aae2fcbc to your computer and use it in GitHub Desktop.
Save IvBaranov/02cccc6e2dc4f71e74015740aae2fcbc to your computer and use it in GitHub Desktop.
Android drag and drop
dropView.setOnDragListener((view, event) -> {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
// on entered view
break;
case DragEvent.ACTION_DRAG_EXITED:
// on exited view
break;
case DragEvent.ACTION_DROP:
// on dropped in view
break;
case DragEvent.ACTION_DRAG_ENDED:
// on drag ended
default:
break;
}
return true;
});
dragView.setOnTouchListener((view, motionEvent) ->
{
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
// drag started
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
view);
view.startDrag(data, shadowBuilder, view, 0);
return true;
} else {
return false;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment