Chr*_*911 5 java android listview filter adapter
我想过滤我listView
使用一个EditText
盒子并使用适配器getFilter()
功能.它工作得很好,直到我在文本框中放置一个空格字符.
编辑:这是一个SimpleAdapter而不是ArrayAdapter
如果我的列表中包含以下单词:{"Apple","Banana","Red Apple"}如果我输入"apple",它将返回包含苹果字样的所有项目(Apple和Red Apple).如果我输入"apple",它将不会返回任何内容.
有任何想法吗?这是代码:
searchBox = (EditText) findViewById(R.id.searchBox);
searchBox.addTextChangedListener(filterTextWatcher);
Run Code Online (Sandbox Code Playgroud)
和
private TextWatcher filterTextWatcher = new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
myAdapter.getFilter().filter(s.toString());
}
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3305 次 |
最近记录: |