onInterceptTouchEvent's ACTION_UP and ACTION_MOVE never gets called
Asked Answered
P

1

4

Log is never logging ACTION_UP or ACTION_MOVE(which i removed from the code example for shortening)

Here is my shorten version of the code:

 public class ProfileBadgeView extends LinearLayout {

    Activity act;

    public ProfileBadgeView(Context context) {
        super(context);
    }

    public ProfileBadgeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ProfileBadgeView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void initView(Activity act) {
        //..init
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            logIntercept("ACTION DOWN");
        } else if (ev.getAction() == MotionEvent.ACTION_UP) {
            logIntercept("ACTION_UP");
        }
        return false;
    }

    @Override
        public boolean onTouchEvent(MotionEvent ev) {
        return true;
}


    private void logIntercept(Object obj) {
        Log.i(this.getClass().getSimpleName() + " INTERCEPT :", obj.toString());
    }



}
Phippen answered 22/1, 2014 at 16:10 Comment(1)
Put a Toast outside the conditions and check if the toast is displayedKiel
S
13

Your onInterceptTouchEvent method is not called after ACTION_DOWN event because you return true in onTouchEvent method. So all the other events are sent in onTouchEvent and not in onInterceptTouchEvent any more:

Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

You will receive the down event here. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.

http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent)

Sotos answered 22/1, 2014 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.