public class Listeners<T extends 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()
}
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)
| Constructor and Description |
|---|
Listeners(kotlin.reflect.KClass<T> listenerType)
Allows you to add listeners for a particular event into your component.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T listener)
Registers a new listener. Registering same listener multiple times has no further effect.
|
T |
getFire()
Use the returned value to fire particular event to all listeners.
|
kotlin.reflect.KClass<T> |
getListenerType() |
void |
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.
|
public Listeners(kotlin.reflect.KClass<T> listenerType)
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()
}
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)
public void 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.
public void 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.
public T getFire()
Use the returned value to fire particular event to all listeners.
Returns a proxy of type T. Any method call on this proxy is propagated to all listeners.
public kotlin.reflect.KClass<T> getListenerType()