开发者

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;
}


  1. The class that implements runQueryOnBackgroundThread must implements filterable. And let's assume this class is called A.
  2. 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜