Avoid calling a listener more than once! Add the clicklistener in the constructor of the widget not a method called over and over. Every time you call a method with a clicklister, you add another observer to that object. Then if you want to do something with that object, you may cause multiples of something to happen, which is annoying!
private HorizontalPanel pWidgetContent = new HorizontalPanel();
private PushButton bPushMe = new PushButton(”Push Me”);
/**
* constructor - init a widget maybe
*/
public MyClass() {
initWidget(pWidgetContent);
bPushMe.addClickListener(this);
}public void drawMorePanelsEveryOnceInWhile() {
//don’t stick listener here
//bPushMe.addClickListener(this);
}public void myMethod() {
//do something
}public void onClick(Widget sender) {
if (sender == bPushMe) {
this.myMethod();
}
}
Add A Comment
You must be logged in to post a comment.
