0

I have a viewpager, one of its fragment has a button which if you tap produces two more buttons along the side that you can swipe to touch(much like picking up the phone gesture in android).

(b1)----------(b2)---------(b3)

b2 on touching produces b1 and b3

everything is fine, except that when i try to move my finger horizontally, the touch events of the viewpager come into picture and the page swipe happens.

I have been able to make it happen in an activity without viewpager so there is no one to capture the sideways gestures.

I thought of the following options

  1. i tried

    getActivity().findViewById(R.id.viewpager).onTouchEvent(event)

inside the onTouch of the button but i get "Exeption Dispatching Input Event" in logcat once i go outside the bounds of button.

  1. trying to disable the viewpager touch event, but i havent been able to do that ?

  2. Creating a new transparent fragment or activity which can overlay the fragment, but i am unable to dispatch the touchevent to that activity or fragment ?

Please tell me either of them.

  1. disabling the viewpager touch event?

  2. dispatching the touch to another activity or fragment?

  3. If i could create a custom View that has 3 buttons?

user3439988
  • 593
  • 1
  • 6
  • 9

1 Answers1

0

You can pretty easily disable the ViewPager's touch by extending the class and returning false from its onInterceptTouch method. Details here. Hopefully, disabling touch there will clear your other error.

Community
  • 1
  • 1
JASON G PETERSON
  • 2,193
  • 1
  • 18
  • 19
  • i know that, but I want to temporarily disable the viewpager touch. when the user presses the button, the viewpager should be disabled and on event UP the viewpager should be re-enabled. – user3439988 Dec 15 '14 at 19:00
  • is it possible to dynamically disable the touch on viewpager – user3439988 Dec 15 '14 at 19:00
  • Pass a Boolean to the custom ViewPager? `if (depressed) { return false; } { else` . . . You can use an `onTouchListener` on your buttons which will give you method for `ACTION_UP`/`ACTION_DOWN` so you can set the state of the Boolean properly. – JASON G PETERSON Dec 15 '14 at 19:06
  • 1. cant i directly do this: getActivity().findViewById(R.id.viewpager).onTouchEvent(new MotionEvent().setAction(MotionEvent.ACTION_UP)); – user3439988 Dec 15 '14 at 19:11
  • I think you solution should work. let me check and give up an up. – user3439988 Dec 15 '14 at 19:16