views:

495

answers:

3

My application has a custom view which contains other custom views of a different type. The subviews have their own click listeners (which I can't change, as these are in 3rd party libraries). How can I intercept a user's click at the level of my view to do some processing, and then pass the click on to the proper subview?

A: 

I'm not entirely sure about this, but in Java what I would do is define various subview objects in my main view and simply send those to the draw/paint function. That way I'd only have ONE click listener which would be in the view anyways.

Can you do something like that in Android?

piggles
+1  A: 

Justin, you can play with dispatchTouchEvent() or onInterceptTouchEvent().

Romain Guy
Looks like what I need, thanks!
Justin
A: 

I am trying to call the subview listerners or touch event, but I am not sure how to get the subview from the parent view.

When I hardcode and use getChildAt(0), it works. But I have more than one view, and I want to get the particular view which has been touched.

Please help me.

getFocusedChild() is returning null.

Pria
Pria, if your children have onInterceptTouchEvent() already, all you need to do is return false in the parent's onInterceptTouchEvent() and the event will be passed through to the children.
Justin
I still have no luck :(My ViewGroup has - onInterceptTouchEvent(...){ return false;}My View has - onInterceptTouchEvent(...){Toast.makeText(context, "Touched Intercept: " + getId(),Toast.LENGTH_SHORT).show(); return true;}Now while debugging, the control went to the ViewGroup - onInterceptTouchEvent(), but then was not passed to the View - onInterceptTouchEvent() Can you plz point out where have I gone wrong?
Pria