@Override
public boolean onDrag(View view, DragEvent dragEvent) {
// Get the drag drop action.
int dragAction = dragEvent.getAction();
if (dragAction == dragEvent.ACTION_DRAG_STARTED) {
// Check whether the dragged view can be placed in this target view or not.
} else if (dragAction == dragEvent.ACTION_DRAG_ENTERED) {
// When the being dragged view enter the target view.
return true;
} else if (dragAction == dragEvent.ACTION_DRAG_EXITED) {
// When the being dragged view exit target view area.
return true;
} else if (dragAction == dragEvent.ACTION_DRAG_ENDED) {
// When the drop ended.
return true;
} else if (dragAction == dragEvent.ACTION_DROP) {
// When drop action happened.
// คำนวณในส่วนนี้
// Get clip data in the drag event first.
ClipData clipData = dragEvent.getClipData();
// Get drag and drop item count.
int itemCount = clipData.getItemCount();
// If item count bigger than 0.
if (itemCount > 0) {
// Show a toast popup.
Toast.makeText(context, Integer.toString(itemCount*5) + "Baht", Toast.LENGTH_LONG).show();
return true;
}
} else if (dragAction == dragEvent.ACTION_DRAG_LOCATION) {
return true;
} else {
Toast.makeText(context, "Drag and drop unknow action type.", Toast.LENGTH_LONG).show();
}
return false;
}