我在黑莓中使用了AutoCompleteField
并使用BasicFilteredList
过滤了文本。它在黑莓SDK 5.0及更高版本中运行良好。但是,搜索正在根据键入的单词工作。如果我有一个文本字符串如下。
T 115 Centro Galleria购物中心,Cnr Old Collier和Walters Road Morley WA 1522
只有当我输入152时才会过滤字符串,但是如果我使用522则它不能过滤。我希望它应该根据我的要求进行过滤,因为它们出现在上面的搜索字符串中。请帮我解决这个问题。
以下是用于创建AutoCompleteField
import net.rim.device.api.collection.util.BasicFilteredList;
import net.rim.device.api.collection.util.BasicFilteredListResult;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.AutoCompleteField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.util.CharacterUtilities;
public class AutoCompleteFieldApp extends UiApplication {
public static void main(String[] args) {
AutoCompleteFieldApp app = new AutoCompleteFieldApp();
app.enterEventDispatcher();
}
AutoCompleteFieldApp() {
pushScreen(new HomeScreen());
}
}
class HomeScreen extends MainScreen {
LabelField selectedText;
public HomeScreen() {
setTitle("Autocomplete Text Field Demo");
selectedText = new LabelField();
BasicFilteredList filterList = new BasicFilteredList();
String[] address = { "T 115 Centro Galleria Shopping Centre, Cnr Old Collier and Walters Road Morley WA 1522",
"1423 SEAVIEW POINT POINT COOK VIC 2674",
"Lot 1498 Yarraman Road Wyndham Vale VIC 3795",
"Lot 3506 Witchmount Close Hillside VIC 4055",
"6 Paas Place Williamstown VIC 4233",
"Lot 99 14 James Close Sunbury VIC 4502",
"1 Charlotte Street Clayton South VIC 4779" };
filterList.addDataSet(1, address, "address", BasicFilteredList.COMPARISON_IGNORE_CASE);
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList){
public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
ListField _list = getListField();
if (_list.getSelectedIndex() > -1) {
if(selectedText!=null){
BasicFilteredListResult result = (BasicFilteredListResult) selection;
selectedText.setText(result._object.toString());
}
}
}
};
add(autoCompleteField);
AutoCompleteField autoCompleteField2 = new AutoCompleteField(filterList){
public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
ListField _list = getListField();
if (_list.getSelectedIndex() > -1) {
if(selectedText!=null){
BasicFilteredListResult result = (BasicFilteredListResult) selection;
selectedText.setText(result._object.toString());
}
}
}
};
TextFilter filter = new TextFilter() {
public char convert(char c, int status) {
if (!validate(c))
return 0;
return c;
}
public boolean validate(char c) {
return CharacterUtilities.isDigit(c);
}
};
autoCompleteField2.getEditField().setFilter(filter);
add(autoCompleteField2);
add(selectedText);
}
}
提前致谢。
答案 0 :(得分:0)
我没试过这个,但我认为这应该有效。首先覆盖getMatchedKeywords
中的BasicFilteredList
。您应该返回将触发匹配的关键字。因此,对于您的情况“1522”,您应该返回 {“1522”,“522”,“22”,“2”} 。来自BasicFilteredListResult
的对象应为您的“1522”。正如您所看到的,如果您在可搜索的句子中有多个单词,那么生成所有这些子字符串会更加痛苦。但这是我认为的API的局限性。
可能还有另一种解决方案。