3
votes

Sorry for the complex question let me explain. I've created a custom widget that handles some ontouch events. What i want to do is when i start a touch event on that custom widget (onDown) i want that widget to keep handling these event even if the absolute coordinations are not in that widget.

I have a scrollview and on top of that(inside the scrollview) a widget that handles (left - right) scrolls. But if i move the finger vertically the ontouch events are consumed and handled by the scollview. If there a way to forbit scrollview to handle touch events , or better force the custom widget to keep handling the touchEvent, if i start the ontouchEvent inside the custom widget?

UPDATE I came across that http://groups.google.com/group/android-framework/browse_thread/thread/2cdd4269dfb2772e?pli=1 .

That works in my case if the custom widget is NOT inside a scrolling view like "ScrollView". Trying to solve the "Beeing inside a scrolling object. How to not send these on touchevents to the parent? Returning true doesn't solve the problem

2
Have you tried instantiating your own ScrollView and overriding the onTouchEvent()?Paul Lammertsma
No I want the solution to be on the widget itself. Sure I can block scrolling messing with the scv but next time it can be within a horizontalscv or a listview.weakwire

2 Answers

8
votes

In your widget's onTouch handler (e.g. during ACTION_MOVE), call the parent.requestDisallowInterceptTouchEvent(true). That method basically is asking the parent (in your case the scrollview) and its ancestor not to intercept the touch event.

1
votes

You will need to implement a special subclass of ScrollView, which allows your widget to tell it to disable scrolling when desired (so it won't start scrolling after enough movement and take events from your widget). The custom ScrollView can override this method:

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

When you don't want the base class to consume touch events for scrolls, return false here instead of calling the base implementation.