2011-11-30 80 views
0

我已經添加到MainScreen和類實現FieldChangeListener。問題在於,當我輸入文本並按下按鍵時,它會處理,但當我刪除文本時,按下該按鍵則不會。下面是我添加了它:BB AutoCompleteField事件沒有被處理

/// 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(); 
     } 
    }; 
+0

我想你忘了添加autoCompleteField.setChangeListener(this); –

+0

nope ...而是我刪除它,因爲@Arhimed指出,「AutoCompleteField」已經聽取了它自己。 – tipycalFlow

回答

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)偵聽本身。

+0

我刪除了'autoCompleteField.setChangeListener(this);' - 你是對的!我有其他的領域實現'FieldChangeListener',所以我一直聽着它與其他按鈕在重疊字段(字段字段,int上下文)'方法,但奇怪的是它沒有工作!我在問題 – tipycalFlow

+0

@tipycalFlow中添加了這個:從你的評論我仍然懷疑你是否修復它。 :) –

+0

是的,我沒有:( – tipycalFlow