我有一个自定义的Oracle,其中包含要传递给SuggestBox的对象。然后,我需要在从de SuggestBox中选择一个对象时将其取回。
public HandlerRegistration addSelectionHandler(SelectionHandler<SuggestOracle.Suggestion> handler)问题是我没有建议。我有"CustomSuggestion“这个词。我阅读了de API,并尝试编写一个实现接口HasSelectionHandlers的自定义SuggestBox,但我做不到,因为SuggestBox有该接口的实现。我得到了错误:
The interface HasSelectionHandlers cannot be implemented more than once with different arguments: HasSelectionHandlers<SuggestOracle.Suggestion> and HasSelectionHandlers<CustomSuggestion>你能帮帮我吗?对不起,我的英语不好。
发布于 2010-12-15 00:44:53
我不太明白你的问题。看一下下面的例子(非常基础,但你应该对如何处理自定义建议有所了解)。希望这能有所帮助:
public void onModuleLoad() {
SuggestBox box = new SuggestBox(new CustomOracle<CustomSuggestion>());
box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
@Override
public void onSelection(SelectionEvent<Suggestion> event) {
String value = ((CustomSuggestion) event.getSelectedItem()).fSomeOtherValue;
Window.alert(value);
}
});
RootPanel.get().add(box);
}
private class CustomOracle<CustomSuggestion> extends SuggestOracle {
private LinkedList<Starter.CustomSuggestion> fStore;
public CustomOracle() {
fStore = new LinkedList<Starter.CustomSuggestion>();
fStore.add(new Starter.CustomSuggestion("2", "two", "foo"));
fStore.add(new Starter.CustomSuggestion("22", "twenty-two", "bar"));
fStore.add(new Starter.CustomSuggestion("222", "two-hundred twenty-two", "w000t"));
}
@Override
public void requestSuggestions(Request request, Callback callback) {
String query = request.getQuery();
LinkedList<Starter.CustomSuggestion> result = new LinkedList<Starter.CustomSuggestion>();
for (Starter.CustomSuggestion entry : fStore) {
if (entry.fDisplay.contains(query)) {
result.add(entry);
}
}
callback.onSuggestionsReady(request, new Response(result));
}
}
private class CustomSuggestion implements Suggestion {
private String fReplace;
private String fDisplay;
private String fSomeOtherValue;
public CustomSuggestion(String display, String replace, String someOtherValue) {
fDisplay = display;
fReplace = replace;
fSomeOtherValue = someOtherValue;
}
@Override
public String getDisplayString() {
return fDisplay;
}
@Override
public String getReplacementString() {
return fReplace;
}
}https://stackoverflow.com/questions/4418557
复制相似问题