Tushar Ahirrao
Tushar Ahirrao

Reputation: 13125

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

I want to add ClickHandler to the < li> tag

please help me ...

Upvotes: 3

Views: 2441

Answers (3)

joscarsson
joscarsson

Reputation: 4859

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).

Upvotes: 0

Iker Jimenez
Iker Jimenez

Reputation: 7245

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.

Upvotes: 2

jrydberg
jrydberg

Reputation: 629

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

Upvotes: 2

Related Questions