Reputation: 13125
I want to add ClickHandler to the < li> tag
please help me ...
Upvotes: 3
Views: 2441
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
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
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