I am creating a custom widget in GWT extending Composite and implementing ClickHandler. I have already implemented the method onClick, but the clickEvent does not work. What method should I additionally implement in the class in order the clickEvent to work? May be HandlerRegistration? How?
If you want your widget to behave like clickable GWT widgets you should use com.google.gwt.event.dom.client.HasClickHandlers interface.
public class MyWidget extends Widget
implements HasClickHandlers
{
public HandlerRegistration addClickHandler(
ClickHandler handler)
{
return addDomHandler(handler, ClickEvent.getType());
}
}
Try
this.addClickHandler( myClckHandler ) ;
or if not available
this.addDomHandler( myClckHandler , ClickEvent.getType()) ;
this should works
edit==> this should works:
public class Foo extends Composite {
private ClickHandler myClkHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Overnuts is the best !") ;
}
};
public Foo() {
initWidget(this) ;
this.addDomHandler( myClkHandler, ClickEvent.getType()) ;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With