gwt problem with HandlerRegistration

北城以北 提交于 2019-12-02 21:26:10

问题


I have a problem. 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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/4715034/gwt-problem-with-handlerregistration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!