2011-11-16 63 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) { 


     } 

    };