AutoCompletetextView with CursorLoader

I am changing the application to use CursorLoader instead of startManagingCursor ....

And I have one AutoCompleteTextView, SimpleCursorAdapter and in my implementation of setFilterQueryProvider, in the "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 work with CursorLoader?

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

bundleFilter will have text retrieved from textwatcher.

Can this approach be used? Is it better to do this in this case?

+4
source share
1 answer

This is a great approach, according to the Android developer website:

Bootloader reboot:

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

+3
source

Source: https://habr.com/ru/post/1485406/


All Articles