开发者

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();
        }
    }
}));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜