Android Honeycomb - how to show suggestions for SearchView when query text is empty?

I added a SearchView to the ActionBar of my application and set up SuggestionsProvider using SearchableInfo. Suggestions really work well, except that offers are not displayed when the text of the search query is empty. I found that my offer provider is not being requested for offers, even if searchSuggestThreshold is set to 0.

The closest I came to the decision was to use setOnQueryTextFocusChangeListener, and inFocusChange to exchange the cursor of the SearchView sentence adapter. Thus, I see that the sentence falls out with the correct height, however the text of the sentence is not displayed.

This is how I request a cursor to display sentences for empty text.

Cursor emptySuggestions = getContentResolver().query( Uri.parse("content://my.authority/search_suggest_query/test"), null, null, null, null); 

Is there a way to formulate sentences correctly?

Of course, there is always the opportunity to show your own ListPopupWindow when the search query is empty, but I would like to avoid this if there is no easy way to reuse the layout used in SearchView.

+4
source share
2 answers

I figured out how to invoke a search by query to request my offer provider for empty search text:

  _searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) return; String query = _searchView.getQuery().toString(); _searchView.setQuery(query, false); } }); 
+2
source

In addition to manually starting the onQueryTextChange () method above, the threshold value of SearchView.SearchAutoComplete must be set to zero

 SearchView.SearchAutoComplete sac = (SearchView.SearchAutoComplete) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); if (sac != null) { sac.setThreshold(0); } 
+1
source

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


All Articles