Reputation: 2189
I'm trying to filter the contacts list by modifying the selection of my cursor when an OnTextChange happens in my EditText. The problem: the list stays as it is, i.e. it does not get updated as per the filter. What am I doing wrong? I suspect it's my sql query (specifically GLOB part)?
digitsText.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence s, int start, int before, int count){
filterText = digitsText.getText().toString();
WHERE_CONDITION = ContactsContract.Data.DATA1 + " GLOB '*" + filterText + "*'";
cursor = getContentResolver().query(URI, PROJECTION, WHERE_CONDITION, null, SORT_ORDER);
startManagingCursor(cursor);
setListAdapter(adapter);
}
});
Upvotes: 0
Views: 433
Reputation: 1007296
While you generate a new Cursor
, you do not actually do anything with it. You need to either:
swapCursor()
on your CursorAdapter
, if you are on API Level 11 or higherchangeCursor()
on your CursorAdapter
(which may be the better option anyway, if you will not be needing the old Cursor
, as changeCursor()
will close it for you)CursorAdapter
and call setListAdapter()
using the new adapterUpvotes: 1