我将从SimpleCursorAdapter为listview创建一个过滤器。我可以通过我的例子看到Toast,但过滤器没有发生任何事情。我找到了一个setFilterQueryProvider的例子。但我不知道实现这一点。这是我的代码:
Cursor entryCursor = mDatabase.query(
"entrys",
new String[] {
"_id",
"name",
"address"
},
null, null, null, null, null);
startManagingCursor(entryCursor);
final SimpleCursorAdapter entryAdapter =
new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
entryCursor,
new String [] {"name",
"address"},
new int[] { android.R.id.text1,
android.R.id.text2}
);
setListAdapter(entryAdapter);
final ListView mList = (ListView) findViewById(android.R.id.list);
mList.setAdapter(entryAdapter);
final EditText et_search = (EditText) findViewById(R.id.listview_search);
et_search.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Abstract Method of TextWatcher Interface.
entryAdapter.getFilter().filter(s.toString());
Toast.makeText(getApplicationContext(), "Text changed", Toast.LENGTH_SHORT).show();
}
});