[英]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?当然,您可以通过循环将 onclick 分配给所有子视图,但是是否有机会将 click 事件挂在父元素上,然后在所需的子视图上接收事件,例如在 html /js 通过事件目标?
You can setup an onClickListener()
for the parent and then inside that you can delegate the click using child.performClick()
.您可以为父级设置 onClickListener(
onClickListener()
,然后在其中可以使用child.performClick()
委派点击。 if you cant to know more, you can reference https://developer.android.com/reference/android/view/View.html#performClick()如果您无法了解更多信息,可以参考https://developer.android.com/reference/android/view/View.html#performClick()
The code would look something like this:代码看起来像这样:
parent.setOnClickListener {
child.performClick()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.