Is it possible to callback to multiple listeners?
callback, java
Solution
It's very likely that you will need to make a List of listeners, then iterate through each one calling `updateUI()`. Of course, you also need an `addListener()` method so that you don't overwrite.
class CommInt {
private List <OnNotificationEvent> listeners= new ArrayList <OnNotificationEvent>();
public void addNotificationListener(OnNotificationEvent notifListner) {
listeners.add (notifListener);
}
private void parseMsg(Message msg) {
if (msg.getType() == x) {
for (notifListener : listeners){
notifListener.updateUI();
}
}
}
}
Problem
Is it possible to set multiple listeners using callbacks? I am trying to understand how the callbacks work and I am trying to figure out it that's what I need. I have one UDP messaging class which receives/sends messages. When I parse certain messages, I would like to update multiple UI classes. At the moment I have something like this: ``` class CommInt { private OnNotificationEvent notifListener; public setNotificationListener(OnNotificationEvent notifListner) { /* listener from one UI */ this.notifListener = notifListener; } private parseMsg(Message msg) { if (msg.getType() == x) { notifListener.updateUI(); } } } ``` I need to update another UI as well. The other UI will use the same interface but the body will be different. How is it possible call all listener which are implemented from that interface?