gpt4 book ai didi

gwt - SuggestBox 覆盖 addSelectionHandler

转载 作者:行者123 更新时间:2023-12-04 20:18:19 25 4
gpt4 key购买 nike

我有一个带有要传递给 SuggestBox 的对象的自定义 Oracle。然后我需要在从 de SuggestBox 中选择一个对象时取回它。

public HandlerRegistration addSelectionHandler(SelectionHandler<SuggestOracle.Suggestion> handler)

问题是我没有建议。我有“CustomSuggestion”。我阅读了 de API,并尝试编写一个实现接口(interface) HasSelectionHandlers 的自定义 SuggestBox,但我不能,因为 SuggestBox 具有该接口(interface)的实现。我收到错误:

The interface HasSelectionHandlers cannot be implemented more than once with different arguments: HasSelectionHandlers<SuggestOracle.Suggestion> and HasSelectionHandlers<CustomSuggestion>

你能帮帮我吗?抱歉我的英语不好。

最佳答案

不确定我是否理解您的问题。看看下面的示例(非常基本,但您应该了解如何处理自定义建议)。希望有所帮助:

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;
}
}

关于gwt - SuggestBox 覆盖 addSelectionHandler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4418557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com