I have an onclick event and I need to update some views on a web page according to server response. What is the best way to implement this using listeners and handlers? I think that I should create clickListener and map it to a button, but I don't know how to notify views that they should render some data. For example, I have one presenter (called Presenter) and 3 views (View1, View2, View3). And the first way is to do something like this:
public class Presenter {
private View1 view1;
private View3 view2;
private View3 view3;
private Button button;
protected void doSmth() {
button.setClickListener(new ClickListener() {
view1.update();
view2.update();
view3.update();
});
}
}
But that's obviously bad approach. The good way (I think) is to do next:
public class Presenter {
private Button button;
protected void doSmth() {
button.setClickListener(new ClickListener() {
//push object that will trigger handlers in views.
});
}
//this is the same for all views
public class View {
protected void handleClickInPresenter() {
//render the data
}
}
But I can't understand how to implement this way. Ask for your help.Thanks.