LI element with a clickhandler
I read up on this post
https://groups.google.com/forum/?fromgroups=#!topic/Google-Web-Toolkit/Zg5XQc9aCaI
for the whole day I am stuck on this issue, this article seems right on the topic, but the code was abbreviated to the point I can not get it working.
class MyList extends Widget implements HasClickHandlers {
public MyList() {
// TODO: build your DOM tree here
setElement(ulElement);
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
addDomHandler(handler, ClickEvent.getType());
}
// Helper method, not strictly necessary but very helpful
// You could either return a LIElement or the index of the item in
the list as an int
public int getItemFromEvent(DomEvent<?> event) {
// TODO: see my previous message about how to implement it
// see also the code for HTMLTable.getCellForEvent
}
}
public MyList() {
// TODO: build your DOM tree here
setElement(ulElement);
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
addDomHandler(handler, ClickEvent.getType());
}
// Helper method, not strictly necessary but very helpful
// You could either return a LIElement or the index of the item in
the list as an int
public int getItemFromEvent(DomEvent<?> event) {
// TODO: see my previous message about how to implement it
// see also the code for HTMLTable.getCellForEvent
}
}
so where do I actually add the clickhandler?
I tried
this.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
int a = 0;
}
});
the compiler does not complain but this handler does not respond to mouse clicks.
I tried
anchorLink.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
int a = 0;
}
});
where anchorLink is an anchorElement, the compiler complains addClickHandler is not a method of anchorLink.
Can someone help me complete the posted sample code.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/2CaQ-KByHl0J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home