Android route / bubble events because a control is consuming the onClick event
I have a custom view with an ImageView and a TextView on it and implemented the onClickListener for my custom view. The problem is, that the ImageView is consuming the onClick-event (I just want the user be able to click on my control, no matter where). I could listen to the onClick of the Image/TextView too, but it seems开发者_JAVA百科 dirty to me.
Is there a way to bubble / route Events in Android? Or possible another good solution?
View.onClick()
event does not bubble. Two possible solutions:
Register
OnCLickListener
on you child views and then pass on the event by callingperformClick()
on parent.Use
OnTouchListener
which bubbles up: just returnfalse
in child view'sonTouch()
method. This is more work as you have to account for touch-down & lift-up in order to emulate click.
Have you set the onClickListener
in your custom view?
Set your custom view as clickable.
I don't recommend on setting any click listener in the child views.
Does it work now?
精彩评论