Situation
I have data coming from a SQLite DataProvider on the phone. My fragment extends ListFragment and implements LoaderManager.LoaderCallbacks<Cursor>. I am looking to have a SearchView widget to allow filtering of the ListView. In onActivityCreated, I am using SimpleCursorAdapter to find columns to my own xml layout. In onCreateLoader, I am using CursorLoader.
There are two approaches I can think of based on research.
Filter approach
I can get a filter from the adatper. My code:
Fragment frag = getView().findViewByTag(....);
Filter f = ((SimpleCursorAdapter) frag.getListView().getAdapter()).getFilter();
f.filter(<searchText>);
However the above code does nothing.
Re-launch loader with selection args
Relaunch the loader with right search texts, as stated here
Bundle args = new Bundle();
args.putString(SEARCH_TERM, text);
getLoaderManager().restartLoader(0, args, this);
Above seems to work.
The question is: is this by design that filter does not work with SimpleCursorAdapter? How should Filter interface be used?
It seems like I am just re-inventing the wheel of the Filter design.