开发者

How can i add clickHandler to the <li> tag in GWT?

开发者 https://www.devze.com 2022-12-16 13:50 出处:网络
I want to add ClickHandler to the< li> tag 开发者_运维百科please help me ...You could use a FocusWidget once you\'ve got hold of the Element.There\'s a FocusWidget constructor taking a single Ele

I want to add ClickHandler to the < li> tag

开发者_运维百科please help me ...


You could use a FocusWidget once you've got hold of the Element. There's a FocusWidget constructor taking a single Element. After that you can just call addClickHandler


You need to have the <li> tag as a widget that implements the HasClickHandler interface. Then you can instantiate a ClickHandler and add it to the <li> widget.


This is what I'm currently using. It works, but I'm not sure if it's the right approach.

public class ListItem extends HTMLPanel implements HasClickHandlers {
    public ListItem(String html) {
        super(html);
    }

    @Override
    protected void setElement(Element elem) {
        super.setElement(DOM.createElement("li"));
    }

    @Override
    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return addDomHandler(handler, ClickEvent.getType());
    }
}

This allows using UiBinder to define a ListItem which can then contain arbitrary HTML (and be clickable).

0

精彩评论

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