Code example for DragEvent

Methods: getAction, getClipData

0
	} 
 
	@Override 
	public boolean onDrag(View v, DragEvent event) {
		// Defines a variable to store the action type for the incoming event 
		final int action = event.getAction();
 
		CharSequence dragData;
		// Handles each of the expected events 
		switch (action) {
 
		case DragEvent.ACTION_DRAG_STARTED:
 
			// Determines if this View can accept the dragged data 
			if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
				 
				textView.setBackgroundColor(Color.BLUE);
 
				// returns true to indicate that the View can accept the dragged 
				// data. 
				return true; 
 
			} else { 
				// Returns false. During the current drag and drop operation, 
				// this View will 
				// not receive events again until ACTION_DRAG_ENDED is sent. 
				return false; 
			} 
 
		case DragEvent.ACTION_DRAG_ENTERED:
			 
			textView.setBackgroundColor(Color.GREEN);
			 
 
 
			return true; 
 
		case DragEvent.ACTION_DRAG_LOCATION:
 
			return true; 
 
		case DragEvent.ACTION_DRAG_EXITED:
 
			textView.setBackgroundColor(Color.parseColor("#999999"));
 
			return true; 
 
		case DragEvent.ACTION_DROP:
 
			// Gets the item containing the dragged data 
			ClipData.Item item = event.getClipData().getItemAt(0);
 
			// Gets the text data from the item. 
			dragData = item.getText();
 
			// Displays a message containing the dragged data.