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
You need to implement
onInterceptTouchEvent
and returntrue
when you want to intercept the touch event.Touch events are dispatched to the ViewGroup's
onInterceptTouchEvent
. If that returnsfalse
, the touch events then gets passed to theonTouchEvent
method of each child View of that ViewGroup in reverse drawing order. If no child returnstrue
from that method, then the ViewGroup gets the event in itsonTouchEvent
.http://developer.android.com/training/gestures/viewgroup.html
https://www.youtube.com/watch?v=EZAoJU-nUyI