Srichand Yella Srichand Yella -4 years ago 153
Android Question

Passing touch events to the parent view

I have a custom

in which I implemented touch events so I
am able to scroll through screens using the touchscreen.

My layout hierarchy looks like this:


<ListView />

<ListView />


Now, the problem is that the touch events are being consumed by the
and I am not able to switch the views. It works fine when I
don't have the
. I need to be able to scroll through the
views and scroll the

How do I solve this?

EDIT: I also need the
items to be clickable.

Thanks in advance!

Answer Source

Thank you everyone for answering the question. But I was able to figure it out in a much simpler manner. Since my ViewSwitcher wasn't detecting the touch event, I intercepted the touch event, called the onTouchEvent() and returned false. Here:

public boolean onInterceptTouchEvent(MotionEvent ev)
    return false;

By overriding the onInterceptTouchEvent(), I was able to intercept the touch event in the activity. Then I called the onTouchEvent() in the ViewSwitcher which handles the switching of the ListViews. And finally by returning false, it makes sure that the ViewGroup doesn't consume the event.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download