Ad

ACTION_DRAG_STARTED Gets Called On All Views

- 1 answer

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.

Ad

Answer

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

Ad
source: stackoverflow.com
Ad