start a filter that asks for runQueryOnBackgroundThread
If I implement filtering for an autocomplete
and I override the runQueryOnBackgroundThread()
method, a background thread will be launched which will get me a cursor.
That cursor will be set to my CursorAdapter
, but what else should I do in order to have the entries of the autocomplete
filtered?
Should I set up a filter?
This is my code:
public Cursor runQueryOnBackgroundThread(C开发者_如何学CharSequence constraint) {
if (getFilterQueryProvider() != null) {
return getFilterQueryProvider().runQuery(constraint);
}
String filter="";
if(constraint==null)
filter="";
else
filter=constraint.toString();
Cursor cursor=db.getCursor(filter);
return cursor;
}
- The class that implements runQueryOnBackgroundThread must implements filterable. And let's assume this class is called A.
- setup a listener on a textview so that whenever something changes, you run a.getFilter().filter(s) where "a" is an instance of A and "s" is the text you want to use to as an arguments to runQueryOnBackgroundThread.
精彩评论