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);
}
});
While you generate a new
Cursor, you do not actually do anything with it. You need to either:swapCursor()on yourCursorAdapter, if you are on API Level 11 or higherchangeCursor()on yourCursorAdapter(which may be the better option anyway, if you will not be needing the oldCursor, aschangeCursor()will close it for you)CursorAdapterand callsetListAdapter()using the new adapter