I have a database as follows:
------------------------------
BOOK NAME | BOOK FORMAT | COUNT |
------------------------------
Android | HTML | 1
WPF
I think you've messed up things a bit. Actually SimpleCursorAdapter
already implements Filterable
, so there's no need to reimplement it. Instead in your ListActivity
use smth like this:
private void filterList(CharSequence constraint) {
final YourListCursorAdapter adapter =
(YourListCursorAdapter) getListAdapter();
final Cursor oldCursor = adapter.getCursor();
adapter.setFilterQueryProvider(filterQueryProvider);
adapter.getFilter().filter(constraint, new FilterListener() {
public void onFilterComplete(int count) {
// assuming your activity manages the Cursor
// (which is a recommended way)
stopManagingCursor(oldCursor);
final Cursor newCursor = adapter.getCursor();
startManagingCursor(newCursor);
// safely close the oldCursor
if (oldCursor != null && !oldCursor.isClosed()) {
oldCursor.close();
}
}
});
}
private FilterQueryProvider filterQueryProvider = new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
// assuming you have your custom DBHelper instance
// ready to execute the DB request
return dbHelper.getListCursor(constraint);
}
};