简体   繁体   中英

How to delegate click event from parent (ViewGroup) to child (View) android?

You can, of course, assign onclick to all child views through a loop, but is there such an opportunity to hang the click event on the parent element, and then receive the event on the desired child view, as, for example, in html/js through the event target?

You can setup an onClickListener() for the parent and then inside that you can delegate the click using child.performClick() . if you cant to know more, you can reference https://developer.android.com/reference/android/view/View.html#performClick()

The code would look something like this:

parent.setOnClickListener {
  child.performClick()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM