Code example for DragEvent

Methods: getAction, getClipData

0
        } 
    } 
     
    protected class myDragEventListener implements OnDragListener {
        public boolean onDrag(View v, DragEvent event) {
            final int action = event.getAction();
            switch(action) {
                case DragEvent.ACTION_DRAG_STARTED:
                    if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                        ((ImageView) v).setColorFilter(Color.BLUE);
                        Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_STARTED", Toast.LENGTH_SHORT).show();
                        v.invalidate();
                        return true; 
                    } else { 
                        return false; 
                    } 
                case DragEvent.ACTION_DRAG_ENTERED:
                    ((ImageView) v).setColorFilter(Color.GREEN);
                    Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_ENTERED", Toast.LENGTH_SHORT).show();
                    v.invalidate();
                    return true; 
                case DragEvent.ACTION_DRAG_LOCATION:
                	return true; 
                case DragEvent.ACTION_DRAG_EXITED:
                    ((ImageView) v).setColorFilter(Color.RED);
                    Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_EXITED", Toast.LENGTH_SHORT).show();
                    v.invalidate();
                    return true; 
                case DragEvent.ACTION_DROP:
                    ClipData.Item item = event.getClipData().getItemAt(0);
                    CharSequence dragData = item.getText();
                    Toast.makeText(DragAndDropActivity.this, "Dragged data is " + dragData, Toast.LENGTH_SHORT).show();
                    ((ImageView) v).clearColorFilter();
                    v.invalidate();
                    return true;