I read up on this post
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
}
}
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.