0

I am using OnDragListener to drag and drop image. i have MOTIONEVENT.ACTION_MOVE to implement image moving functionality. At a certain point in the action move, I want to end the drag and remove its shadow. Is it possible to set the action in drag event? Before releasing finger i want to call drop event.

switch(event.getAction()) {

      case MotionEvent.ACTION_MOVE:
           //here i want to remove shadow and stop dragging
           break;
      case DragEvent.ACTION_DROP:break;
   }
Nick Friskel
  • 2,369
  • 2
  • 20
  • 33
android
  • 441
  • 1
  • 5
  • 17

1 Answers1

0

You can implement OnDragListener in your class/ fragments.

          class MyDrag implements OnDragListener {
            Drawable image = getResources().getDrawable(
                            R.drawable.shape_droptarget);

            @Override
            public boolean onDrag(View v, DragEvent event) {
                    int action = event.getAction();
                    switch (event.getAction()) {
                    case DragEvent.ACTION_DRAG_STARTED:
                            // Signals the start of a drag and drop operation
                            break;
                    case DragEvent.ACTION_DRAG_ENTERED:
                           //Signals to a View that the drag point has entered the bounding box of the View
                            v.setBackgroundDrawable(image);
                            break;
                    case DragEvent.ACTION_DRAG_EXITED:
                           //Signals that the user has moved the drag shadow out of the bounding box of the View or into a descendant view that can accept the data.
                            v.setBackgroundDrawable(image);
                            break;
                    case DragEvent.ACTION_DROP:
                            // Signals to a View that the user has released the drag shadow, and the drag point is within the bounding box of the View and not within a descendant view that can accept the data.
                            View view = (View) event.getLocalState();
                            ViewGroup owner = (ViewGroup) view.getParent();
                            owner.removeView(view);
                            LinearLayout container = (LinearLayout) v;
                            container.addView(view);
                            view.setVisibility(View.VISIBLE);
                            break;
                    case DragEvent.ACTION_DRAG_ENDED:
                          //Signals to a View that the drag and drop operation has concluded.
                            v.setBackgroundDrawable(image);
                    default:
                            break;
                    }
                    return true;
            }
    }

for more details refer here Drag and Drop

sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • ya i am using same. but i am also using case MotionEvent.ACTION_MOVE to track move. so in certain point of Action_move case i want to fire DragEvent.ACTION_DROP. – android Dec 13 '16 at 04:31