Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch suggestions immediately in Android searchable before the user has even started typing

Tags:

android

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.

like image 638
dreid Avatar asked Nov 14 '12 16:11

dreid


People also ask

How do you implement app suggestions when you first open?

Enabling suggestions on a device It is the user's choice whether to include suggestions from your application in the Quick Search Box. To enable search suggestions from your application, the user must open "Searchable items" (in Settings > Search) and enable your application as a searchable item.

What is soft input mode in android?

The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus.

How do I customize my SearchView widget?

just do your own search view, it is very simple. you then can include this layout in your activity layout file. This is a simple layout which includes a "search icon" followed by EditText, followed by "clear icon". The clear icon is shown after user types some text.

What is android Intent Action view?

An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.


1 Answers

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();
}
like image 192
dreid Avatar answered Oct 16 '22 08:10

dreid