I have a custom search implemented using SearchView (ActionBar) with a custom adapter and provider. The problem I have is that the query() method of the ContentProvider is called only once, first time I input something in the SearchView! If I continue typing in the view the query is not called so that the list of suggestions does not get updated.
In a fragment I have where SearchView init:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.planning, menu);
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.searchAirportItem).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setOnQueryTextListener(this);
searchView.setOnSuggestionListener(this);
airportSearchAdapter = new AirportSearchAdapter(getActivity());
searchView.setSuggestionsAdapter(airportSearchAdapter);
}
The suggestion adapter AirportSearchAdapter only redefine the layout of suggested items.
The Fragment implements the QueryTextListener and the method onQueryTextChange looks like
@Override
public boolean onQueryTextChange(String newText) {
Bundle data = new Bundle();
data.putString("query", newText);
getActivity().getLoaderManager().initLoader(1, data, this);
return true;
}
The Fragment also implements LoaderCallbacks:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri uri = AirportsContentProvider.CONTENT_URI;
return new CursorLoader(getActivity(), uri, null, null, new String[] { args.getString("query") }, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
airportSearchAdapter.changeCursor(data);
}`
Any idea why the ContentProvider query method is called only once? Not each time I type?