Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

events - Attaching multiple listeners to views in android?

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

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

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

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?

Regards, Lalith

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...