BB AutoCompleteField事件未被处理

时间:2011-11-30 11:24:40

标签: search blackberry listener

我已添加到MainScreen和类实现FieldChangeListener。问题是当我输入文本并按下键时它会处理,但是当我删除文本然后按下键时它不会处理。这是我添加它的方式:

/// search bar
    BasicFilteredList filterList = new BasicFilteredList();
    String[] terms = {"a","b","c","d","e","f","g","h"};
    filterList.addDataSet(1,terms,"search",BasicFilteredList.COMPARISON_IGNORE_CASE);
    autoCompleteField = new AutoCompleteField(filterList){
        public void onSelect(Object selection, int type) {
            if(type == SELECT_ENTER || type == SELECT_TRACKBALL_CLICK || type == SELECT_TRACKWHEEL_CLICK)
                setListView();
        }
   };
//----------------over-ridden method-----------------
public void fieldChanged(Field field, int context) {
    if(field == topBar.getField(0)){
    // do something
    }
    else if(field == topBar.getField(1)){
    // do something
    }
    else if(field == topBar.getField(2)){
    //do something      
    }
    else if(field == autoCompleteField){
        setListView();//debugger never reaches here!
    }
}

编辑最终解决方案就像以下一样简单 -

autoCompleteField = new AutoCompleteField(filterList){
        public void fieldChanged(Field field, int context) {
            setListView();
        }
   };

1 个答案:

答案 0 :(得分:1)

据我了解您的问题,您希望在该字段变空时收到通知。如果这是您所需要的,您可以将注意力转向AutoCompleteField.fieldChanged(Field field, int context)。它是Executed whenever the text in the field changes。因此,您可以覆盖它并检查文本是否为空字符串,然后触发自定义操作。

顺便说一句,在这种情况下,我认为你不应该这样称呼:

autoCompleteField.setChangeListener(this);

因为AutoCompleteField实现了FieldChangeListener,它已经在AutoCompleteField.fieldChanged(Field field, int context)中监听了自己。