Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setOnTouchListener not called on ViewFlipper

I want to listen to touch events for a viewFlipper. I've been able to listen to touch events in my activity and then modify the viewFlipper but these events are fired wherever the user is within the activity and I need to capture touch events specifically on the viewFlipper. I have tried adding setOnTouchListener but it is not called. I'm assuming the viewFlippers children (webviews) are 'consuming' the touch events.

One solution would be to setOnTouchListener's to each of the webviews but this feels like a hack. Does anyone know another way?

Thanks,

Ian

Sorry if this is a double post - but my previous post seems to have vanished.

like image 901
Ian Avatar asked Dec 07 '25 09:12

Ian


1 Answers

Use ViewGroup.onInterceptTouchEvent(MotionEvent)

You should Reference the Android Documentation as it's usage is quite complicated.

Basic Summary of use:

You receive the touch event here. If you want to consume it, return true and control will be passed to the ViewFlipper's onTouchEvent(). Return false and it will continue to be passed to the child. onTouchEvent() should also return true to ensure all further events are returned to the ViewFlipper's method. The child will also receive the original event with the action ACTION_CANCEL.

like image 178
BeRecursive Avatar answered Dec 08 '25 23:12

BeRecursive