0

Touch works, but Dragging doesn't seem to work at all, what is going on?

public class NavMap extends View {
    public NavMap(Context c){
        super(c);
        OnTouchListener touch = (view, motionEvent) -> {
            Log.i("I", "Touch");
            return false;
        };
        OnDragListener drag = (view, dragEvent) -> {
            Log.i("I", "Drag");
            return true;
        };
        setOnDragListener(drag);
        setOnTouchListener(touch);
    } 
}
  • There's quite a bit more to drag and drop than just setting that listener. For starters, you have to initiate the drag yourself; it doesn't happen automatically. Have a look at this dev page: https://developer.android.com/develop/ui/views/touch-and-input/drag-drop. – Mike M. Oct 30 '22 at 21:40
  • I should've also mentioned that since you're subclassing `View`, it would make more sense to override its `onTouchEvent()` method, rather than setting an `OnTouchListener`, which is for external use, basically. This also leads to the point that you might not want your `View` handling its own `OnDragListener`, but you'll have to decide where to fit that into your design, once you've seen how Android's drag and drop works overall. – Mike M. Oct 30 '22 at 23:25

0 Answers0