Android: On touch event not received by parent view

2.8k Views Asked by At

I have a relative layout R1 as a custom view for an expandable list view.

Now inside R1, i have one Image view I1 and another relative layout R2, both being siblings.

I have set on click listeners for both R2 and I1. And all works fine. But i want to move the whole custom view R1 on certain touch conditions. So i have set OnTouchListener for R1. But when ever i touch the list item, it is never received by R1.

I have tried searching but nothing works. Could someone please help me figure out how to get touch event received by R1 and then if it does not use it, then it should be passed on to I1 and R2.

Thanks, Sunny

1

There are 1 best solutions below

1
On

You need to implement onInterceptTouchEvent and return true when you want to intercept the touch event.

Touch events are dispatched to the ViewGroup's onInterceptTouchEvent. If that returns false, the touch events then gets passed to the onTouchEvent method of each child View of that ViewGroup in reverse drawing order. If no child returns true from that method, then the ViewGroup gets the event in its onTouchEvent.

http://developer.android.com/training/gestures/viewgroup.html

https://www.youtube.com/watch?v=EZAoJU-nUyI