1

I have a ViewPager component, and inside the fragment, there is a WebView component, I want to detect user's tap on screen, and at the same time, user can swipe also.

Currently I am settings the onTouchListener on ViewPager like this: vPager.setOnTouchListener(new View.OnTouchListener() { float oldX = 0, newX = 0, sens = 5;

 @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: oldX = event.getX(); break; case MotionEvent.ACTION_UP: newX = event.getX(); if (Math.abs(oldX - newX) < sens) { tap(); return true; } oldX = 0; newX = 0; break; } return false; } }); 

I find the listener is triggered only when I swipe left and right, when I swipe up and down, it's not triggered. I am swiping on the WebView component, and it has long content which need scroll.

1 Answer 1

1

You're looking only for the X, up and down moves on the Y axis

Sign up to request clarification or add additional context in comments.

5 Comments

no, I add debug point at the entry of onTouch method, its only got triggered when I swipe left and right.
Then the webview gets the event, try implementing it's onTouchListener and see if it gets the event, if so, move the listener as a variable and assign both views to it
because of the pager, it's only interested in the left-right swipes to show next-previous fragment, it's not interested in the up/down.It's pretty much how the android desktop works too, only far more restrictive there, when you swipe left-right you go to the screen and the widgets can only implement up-down gestures and tap
but you know, I can add listener to WebView, but the webView is inside Fragment, I cannot pass the event to ViewPager...
Then try to implement an observer pattern and pass the events to the pager

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.