将多个听众意见的Andr​​oid?多个、听众、意见、oid

2023-09-05 01:26:26 作者:不要说穿

是否可以将多个的onClick监听器按钮的android? 例如:

Is it possible to attach multiple onClick listeners to buttons in android? Example:

btn1.setOnClickListener(listener1);
btn1.setOnCliclListener(listener2);

和被点击的onClick事件的按钮时,无论 listener1 LISTENER2 被触发?

And when the button is clicked onClick event of both listener1 and listener2 are triggered?

在正常的GUI应用程序,我知道,我们可以将多个事件处理程序的事件。是否有可能为Android也还是有什么限制吗?

In normal GUI applications I know that we can attach more than one event handler for an event. Is it possible for android too or is there any restrictions?

问候, Lalith

Regards, Lalith

推荐答案

Android的只支持一般的注册监听器。但是,你可以轻松地创建一个侦听器,只需转发活动,使用复合模式其他的侦听器。

Android only supports one registered listener in general. However, you can easily create a listener that simply forwards the events to other listeners using the composite pattern.