扩展 SuggestOracle 是要走的路!请检查下面的代码...一旦您的实现正确,请将您的 oracle 的新实例传递给您的 SuggestBox。
s.startsWith(userInput)
回答您的核心需求。但是你当然可以写其他条件。
public class MySuggestOracle extends SuggestOracle {
private List<String> data;
public MySuggestOracle(List<String> data) {
this.data = data;
}
@Override
public void requestSuggestions(final Request request, final Callback callback) {
String userInput = request.getQuery();
List<Suggestion> suggestions = new LinkedList<Suggestion>();
for (final String s : data) {
if (s.startsWith(userInput)) {
suggestions.add(new Suggestion() {
@Override
public String getReplacementString() {
return s;
}
@Override
public String getDisplayString() {
return s;
}
});
}
}
Response response = new Response(suggestions);
callback.onSuggestionsReady(request, response);
}
}