Android Drag and Drop ACTION_DRAG_ENDED not firing

后端 未结 2 1400
伪装坚强ぢ
伪装坚强ぢ 2021-02-12 23:43

I\'m really having a time figuring this one out and can\'t find any friends with the relevant experience so far. It\'s my VERY LAST FEATURE before I release my VERY FIRST APP s

相关标签:
2条回答
  • 2021-02-13 00:17

    Views that need to be notified of drag events must register OnDragListeners. If they need to be aware when specific things or types of things move, for instance in order to change their appearance (either to a "DRAG ME HERE!" or a "DON'T YOU DARE DROP THAT ON ME!"). Even if your view is not a valid place to drop the object being dragged, if it needs to be 'drag context aware' so to speak, it registers an OnDragListener and returns true forACTION_DRAG_STARTED.

    The one thing I'm missing from your very thorough question is what exactly you need to be cleaned up? If you just need to do some generic things that are in the scope of the activity, you might consider adding a different OnDragListener to the base RelativeLayout that registers for the events but waits for ACTION_DRAG_ENDED to alert the activity to perform your generic cleanup code

    0 讨论(0)
  • 2021-02-13 00:30

    This may be related to this issue:

    https://code.google.com/p/android/issues/detail?id=25073

    Overriding the dispatchDragEvent function as suggested at that link worked for me:

    @Override
    public boolean dispatchDragEvent(DragEvent ev){
        boolean r = super.dispatchDragEvent(ev);
        if (r && (ev.getAction() == DragEvent.ACTION_DRAG_STARTED
                || ev.getAction() == DragEvent.ACTION_DRAG_ENDED)){
            // If we got a start or end and the return value is true, our
            // onDragEvent wasn't called by ViewGroup.dispatchDragEvent
            // So we do it here.
            onDragEvent(ev);
        }
        return r;
    }
    
    0 讨论(0)
提交回复
热议问题