9

I'm doing some research on ContentProviders and Searchable configurations. I've set up a class that extends a Content Provider with a database that provides suggestions from a database as the user types. This uses the Search Manager paradigm (not a SearchView).

Up to this point, everything works great.

What I'd like to do and am having problems with is to display some suggestions before the user starts typing, after he launches the search. Setting the property 'android:searchSuggestThreshold="0" ' in the searchable.xml only works if the user actually taps into the search textbox after launching it - I would like to display suggestions immediately after the search has been launched (i.e. not wait for the user to do anything else).

Any ideas?

Edit: An example of what I'm talking about is the search functionality in the Google Play Store app - right when a user taps the Magnifying glass for search, a list of recent suggestions immediately pops up.

1 Answer 1

3

Well after spending many hours on this I have finally found a way to achieve what I needed. Here's the answer so perhaps fewer other developers suffer:

The SearchView for the search mode has a text changed listener, and only when the text changes does it fire off a request for suggestions. Obviously, for the initial state nothing has changed so it doesn't request suggestions through the query() function.

In order to "trick" the SearchView into thinking the text has changed, you can do the following:

@Override
public boolean onSearchRequested()
{
  final SearchManager searchManager = (SearchManager) getSystemService( SEARCH_SERVICE );    

  searchManager.startSearch( " ", true, getComponentName(), null, false );

  return super.onSearchRequested();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.