2011-11-16 56 views
6

我有一個適配器,並且我使用ad.getFilter().filter(s);來過濾listView。
如果我在EditText中編寫單個單詞,它會很好用。
如果在一個單詞之後寫入一個空格字符,它將不起作用(不生成任何行)。
我想要做一個名稱和Surmane例如過濾器。 我想在edittext中插入"Mario Rossi"並得到結果..我希望我解釋過。
非常感謝。Android的ListView過濾器

private TextWatcher filterTextWatcher = new TextWatcher() { 

    public void afterTextChanged(Editable s) { 
    } 

    public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
    } 

    public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 
     ad.getFilter().filter(s);    
    } 

}; 
+0

看到這個職位 http://stackoverflow.com/questions/9407428/filter-for-android-listview-space -字符 –

回答

0

你的代碼是完美的,但一些小的失誤有

private TextWatcher filterTextWatcher = new TextWatcher() { 

     public void afterTextChanged(Editable s) { 
       ad.getFilter().filter(s); 
     } 

     public void beforeTextChanged(CharSequence s, int start, int count, 
       int after) { 
     } 

     public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 


     } 

    };