Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 dirty to me.

Is there a way to bubble / route Events in Android? Or possible another good solution?

like image 993
ShadowMare Avatar asked Dec 13 '22 16:12

ShadowMare


1 Answers

View.onClick() event does not bubble. Two possible solutions:

  1. Register OnCLickListener on you child views and then pass on the event by calling performClick() on parent.

  2. Use OnTouchListener which bubbles up: just return false in child view's onTouch() method. This is more work as you have to account for touch-down & lift-up in order to emulate click.

like image 79
Peter Knego Avatar answered Dec 28 '22 05:12

Peter Knego