我正在尝试使用cursoradapter过滤我的listview。这是我到目前为止所尝试的:
CustomAdapter adapter;
Cursor cursor;
etSearch.addTextChangedListener(new TextWatcher (){
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
adapter.getFilter().filter(cs.toString());
}
});
cursor = dbHelper.getAllItemInventoryListings();
adapter = new CustomAdapter(this, cursor);
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence constraint) {
String strItemCode = constraint.toString();
return dbHelper.getAllItemInventoryListings(strItemCode);
}
});
当我尝试它时不会过滤。什么似乎是错的?我们将不胜感激。谢谢。
答案 0 :(得分:5)
尝试在adapter.notifyDataSetChanged();
adapter.getFilter().filter(cs.toString());