1

In my code I have a LinearLayout that has child views, along with creating every child view (via code not xml) I set setOnLongClickListener and setOnDragListener, and it works with a horrible down side effect, that when onDrag gets called on one of the child views, case DragEvent.ACTION_DRAG_STARTED: gets called on all of the child views. why is that?

    childView.setOnDragListener(new View.OnDragListener() {
        @Override
        public boolean onDrag(final View aChildView, DragEvent event) {

            switch (event.getAction()) {
                case DragEvent.ACTION_DRAG_STARTED:
                    Log.d("++++", "Drag Started");
                    aChildView.addView(Early Made up view);
                    break;

                case DragEvent.ACTION_DRAG_ENTERED:

                    break;

                case DragEvent.ACTION_DRAG_EXITED:
                    childView.setBackground(new ColorDrawable(Color.TRANSPARENT));
                    break;

                case DragEvent.ACTION_DROP:
                    childView.setBackground(new ColorDrawable(Color.TRANSPARENT));// In case it got dropped on itself.

                    break;

                case DragEvent.ACTION_DRAG_ENDED:

                    break;

                default:
                    return false;
            }
            return true;
        }

    });

The thing is, that the early made up view appears inside all the child views not just the one that is being dragged.

Jack
  • 693
  • 1
  • 7
  • 25

1 Answers1

0

I believe the answer to my question is that Action Drag Started fired for all views that supports drag and drop in the layout, while Action Drop is for the view that received the drop.

https://stackoverflow.com/a/13301939/5851265

Jack
  • 693
  • 1
  • 7
  • 25
  • Could you please elaborate on how you solved it, I did not understand. For me, ACTION_DRAG_STARTED and ACTION_DRAG_ENDED is triggering for all the views in the layout. – Jatin guglani Mar 23 '23 at 19:37