Remove Click Handler-GWT

How to remove ClickHandler event in GWT? I have added the AddClickHandler () event for the button, and I want to remove the ClickHandler event. I tried the HandlerRegistration method. But he could not remove the handler. Here is a snippet:

notification.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // TODO Auto-generated method stub } }); 

I want to delete a notification handler!

 Note: Notification is the button instance that calls the handler! 
+8
gwt gwt2
source share
2 answers

Each add...Handler method returns a HandlerRegistration interface. This interface contains the removeHandler() method. If you want to remove handlers, just save the returned interface in a variable and call removeHandler when you want to remove the handler.

 HandlerRegistration handler; handler = button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // ... } }); handler.removeHandler(); 
+22
source share

This worked for me, I get a Handler registration when I bind an event,

 closeIconHandlerRegistration = closeImg.addClickHandler( new ClickHandler() { @Override public void onClick( ClickEvent event ) { addCloseClickHanlder(); } } ); 

After that, when I need to remove the handler ...

 if ( this.getCloseButtonHandlerRegistration() != null ) { this.getCloseButtonHandlerRegistration().removeHandler(); this.getCloseImg().addClickHandler( new ClickHandler() { @Override public void onClick( ClickEvent event ) { SaveCancelCommissionChangeEvent saveEvt = new SaveCancelCommissionChangeEvent(); saveEvt.setSave( false ); tabEventBus.fireEvent( saveEvt ); } } ); } 
+1
source share

All Articles