gwt problem with HandlerRegistration
I have a proble开发者_JS百科m. I have a map and added ClickHandler, but after pushing a button I want to remove it. I know that there's some HandlerRegistration but I don't know how to use it. part of my code:
map.addMapClickHandler(new MapClickHandler()
{
public void onClick(MapClickEvent e)
{
...
}
});
can anyone help me?
MapWidget#addMapClickHandler() doesn't return a HandlerRegistration, but the MapWidget class defines a removeMapClickHandler() method:
map.addMapClickHandler(new MapClickHandler() {
@Override
public void onClick(MapClickEvent event) {
// Make sure map is visible to this inner class. It needs
// either to be a member of the enclosing class or final.
map.removeMapClickHandler(this);
}
});
In case you still need this, it took me a while to figure out the solution
final Set<HandlerRegistration> hack = new HashSet<HandlerRegistration>();
hack.add(map.addMapClickHandler(new MapClickHandler() {
public void onClick(MapClickEvent e) {
...
// remove handler here
for (HandlerRegistration hr : hack) {
hr.removeHandler();
}
}
}));
精彩评论