如何在使用Blackberry自动完成字段时将所选项目作为字符串。我现在能够获得所选的索引。我按照
中的说明覆盖AutoCompleteField类中的onSelect方法Autocomplete Class Reference API JDE 5.0
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
{
public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
ListField _list = getListField();
if (_list.getSelectedIndex() > -1) {
Dialog.alert("You selected: "+_list.getSelectedIndex());
// get text selected by user and do something...
}
}
};
答案 0 :(得分:4)
AutoCompleteField的默认实现#onSelect(Object,int)将AutoCompleteField对象的AutoCompleteFieldEditField的文本设置为select参数。所以你可以用那种方式查询String。这是我的意思的片段:
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
{
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}
};
答案 1 :(得分:3)
/*
onSelect
protected void onSelect(Object selection,
int type)
Parameters:
*selection - The selected item*
type - The method of selection. This will be one of SELECT_TRACKWHEEL_CLICK SELECT_TRACKBALL_CLICK SELECT_ENTER
*/
BasicFilteredList filterList = new BasicFilteredList();
String[] days = {"Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"};
filterList.addDataSet(1,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList){
protected void onSelect(Object selection, int type) {
BasicFilteredListResult result = (BasicFilteredListResult) selection;
Dialog.alert("You selected: "+ result._object);
super.onSelect(selection, type);
}
};
add(autoCompleteField);