我在为Datagrid实现双击处理程序时遇到问题。我已经找到了一个解决堆栈溢出的解决方案,我应该解决我的问题,但是,我无法弄清楚:
1. How exactly do I implement it?
2. What is <T>?
我遇到了各种我不理解的错误。问题几乎可以肯定我添加CellPreviewHandler(第6行)
的方式错误(第6行和第8行)
-Type new CellPreviewEvent.Handler(){}必须实现继承的抽象方法CellPreviewEvent.Handler.onCellPreview(CellPreviewEvent)
- 类型new AsynCallBack(String [] []&gt;(){}的onCellPreview(CellPreviewEvent)方法必须覆盖或实现超类型方法
mycode的:
Public Class DataGrid extends Widget{
Timer singleClickTimer;
int clickCount = 0;
int clickDelay = 300;
myDataTable = new DataGrid<String[]>(result.length, resources, KEY_PROVIDER);
myDataTable.addCellPreviewHandler(new Handler<T>(){
@Override
public void onCellPreview(final CellPreviewEvent<T> event) {
if (Event.getTypeInt(event.getNativeEvent().getType()) == Event.ONMOUSEOVER) {
handleOnMouseOver(event);
} else if (Event.getTypeInt(event.getNativeEvent().getType()) == Event.ONCLICK) {
clickCount++;
if (clickCount == 1) {
singleClickTimer = new Timer() {
@Override
public void run() {
clickCount = 0;
handleOnClick(event);
}
};
singleClickTimer.schedule(clickDelay);
} else if (clickCount == 2) {
singleClickTimer.cancel();
clickCount = 0;
handleOnDblClick(event);
}
}
}
});
private void handleOnMouseOver(CellPreviewEvent<T> event) {
Element cell = event.getNativeEvent().getEventTarget().cast();
GWT.log("mouse over event");
}
private void handleOnClick(CellPreviewEvent<T> event) {
Element cell = event.getNativeEvent().getEventTarget().cast();
GWT.log("click event");
}
private void handleOnDblClick(CellPreviewEvent<T> event) {
Element cell = event.getNativeEvent().getEventTarget().cast();
GWT.log("double click event");
}
链接到原始解决方案: adding Double click event in CellTable cell - GWT
答案 0 :(得分:1)
这不是一个非常好的代码(更好的选择是扩展DataGrid类),但如果你不想改变太多,只需用<T>
替换<String[]>
。