4

I´m changing my application to use CursorLoader instead of startManagingCursor....

And I have one AutoCompleteTextView, SimpleCursorAdapter and in my setFilterQueryProvider implementation, in "runQuery" method I have

    mProdutoAdapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence constraint) {

            Cursor cursor = mVendasDb.getProdutos(constraint.toString());
            startManagingCursor(cursor);
            return cursor;
        }
    });

How can I change this part to make it works with CursorLoader?

Should I discard setQueryFilterProvider and use TextWatcher in the AutocompleteTextView and then call getLoaderManager().restartLoader(0, bundleFilter, this)??? I have no idea how to proced!

bundleFilter would have the text came from textwatcher.

Is it ok using this aproach? Is it the best to do in this case?

4

1 回答 1

3

这是一个很好的方法,根据 android 开发者网站:

重新启动加载程序:

要丢弃旧数据,请使用 restartLoader()。例如,当用户查询发生变化时,SearchView.OnQueryTextListener 的这个实现会重新启动加载程序。加载程序需要重新启动,以便它可以使用修改后的搜索过滤器来执行新查询:

于 2013-06-10T14:03:26.370 回答