will
will

Reputation: 1012

AutoCompletetextView with CursorLoader

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?

Upvotes: 4

Views: 1562

Answers (1)

Laurent Dezitter
Laurent Dezitter

Reputation: 710

This is a fine approach, according to the android developer website :

Restarting a Loader :

To discard your old data, you use restartLoader(). For example, this implementation of SearchView.OnQueryTextListener restarts the loader when the user's query changes. The loader needs to be restarted so that it can use the revised search filter to do a new query:

Upvotes: 3

Related Questions