Last active
October 20, 2017 08:09
-
-
Save IvBaranov/02cccc6e2dc4f71e74015740aae2fcbc to your computer and use it in GitHub Desktop.
Android drag and drop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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