-7

Here is code example:

public class SwipeRelativeLayout extends RelativeLayout {

private String TAG = "SwipedListView";
private MotionEvent previous = null;
private MotionEvent start = null;

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

public SwipeRelativeLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();

    String eventType = "";
    switch (action)
    {
        case MotionEvent.ACTION_CANCEL:
        {
            eventType = "ACTION_CANCEL";
        } break;

        case MotionEvent.ACTION_DOWN:
        {
            eventType = "ACTION_DOWN";
        } break;

        case MotionEvent.ACTION_UP:
        {
            eventType = "ACTION_UP";
        } break;

        case MotionEvent.ACTION_MOVE:
        {
            eventType = "ACTION_MOVE";
        } break;
    }

    Log.e(TAG, "onInterceptTouchEvent() Type = " + eventType + " X = " + Float.toString(ev.getRawX()) + " Y = " + Float.toString(ev.getRawY()));

    return true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction() ;
    String eventType = "";
    switch (action)
    {
        case MotionEvent.ACTION_CANCEL:
        {
            eventType = "ACTION_CANCEL";
        } break;

        case MotionEvent.ACTION_DOWN:
        {
            eventType = "ACTION_DOWN";
        } break;

        case MotionEvent.ACTION_UP:
        {
            eventType = "ACTION_UP";
        } break;

        case MotionEvent.ACTION_MOVE:
        {
            eventType = "ACTION_MOVE";
        } break;
    }

    Log.e(TAG, "onTouchEvent() Type = " + eventType + " X = " + Float.toString(event.getRawX()) + " Y = " + Float.toString(event.getRawY()));

    return false;
}
}

Could somebody explain, why I can see onle ACTION_DOWN event into onInterceptTouchEvent()? As has been told in the point 3 at developers.android.com

For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().

I made this, but stil can't see events into onInterceptTouchEvent(), except ACTION_DOWN

Flexo
  • 87,323
  • 22
  • 191
  • 272
Sergey Brazhnik
  • 661
  • 4
  • 13
  • The tone of your questions needs to be professional even if you're frustrated. Anything else is not appropriate and will reduce the likelihood of getting the answer you want. – Flexo Jun 09 '14 at 06:45
  • Sorry, for the title, but the touch event in andriod is whery complex, especially onIntercept(). There is no clear explanation of touch handling in android in the www, even on the developers.android.com – Sergey Brazhnik Jun 09 '14 at 06:59
  • latto, thx for the answer. No it's partly clear. – Sergey Brazhnik Jun 09 '14 at 07:04

1 Answers1

0

For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().

You are returning true from onInterceptTouchEvent, and then you are then returning false from onTouchEvent. You get the ACTION_DOWN, intercept it, then you will stop receiving touch events for the remainder of the stream.

Next time please read the docs, read your code, and don't put crude words in the title of your posts.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • I also have tried to return false from onInterceptTouchEvent() but stil the same result. Only ACTION_DOWN event. – Sergey Brazhnik Jun 09 '14 at 06:45
  • Because you are also returning `false` from `onTouchEvent`. If you return `false` from `onTouchEvent`, it means the view should not receive any more touch events for the remainder of the touch even to stream. – Karakuri Jun 09 '14 at 14:46