-
- All Implemented Interfaces:
-
java.io.Serializable
public final class Listeners<T extends Serializable> implements Serializable
Allows you to add listeners for a particular event into your component.
Say that you have a click listener:
interface OnClickListener { fun onClick(button: Int) }You can add support for click listeners into your Button component easily:
class Button { val onClickListeners = listeners<OnClickListener>() }The clients can then simply register their listeners as follows:
val button = Button() button.onClickListeners.add(object : OnClickListener {})The button can fire an event for all listeners as follows:
onClickListeners.fire.onClick(2)
-
-
Method Summary
-
-
Method Detail
-
add
final Unit add(T listener)
Registers a new listener. Registering same listener multiple times has no further effect.
The equality of the listener is measured by using the standard Any.equals and Any.hashCode.
-
remove
final Unit remove(T listener)
Removes the listener. Removing same listener multiple times has no further effect. Does nothing if the listener has not yet been registered.
The equality of the listener is measured by using the standard Any.equals and Any.hashCode.
-
-
-
-