user2340612
user2340612

Reputation: 10733

Android button auto-fill search field

how can I create in my android app a button that will automatically put the search suggestion into the search bar, so that when you click on the button, the search bar will be automatically filled with the corresponding text?

An example is shown in the image below.

Auto-fill button

Upvotes: 0

Views: 633

Answers (2)

user2340612
user2340612

Reputation: 10733

The solution is to call setQueryRefinementEnabled(true) on the SearchView object

Upvotes: 1

bmat
bmat

Reputation: 2153

Have you looked into AutoCompleteTextView? From the docs:

The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.

EDIT: If you're using a SearchView, the process is much different. Assuming you've already set up the SearchView, you have to provide search suggestions that the system will display as the user types. These can be recent query suggestions or custom search suggestions.

There are several steps involved, but in a nutshell, you will have to create a Content Provider that takes a search query and serves up a list of suggestions (details here). Once you've done this, you can configure your search bar to fill itself in when the user selects a suggestion (details here).

Hope this helps!

Upvotes: 1

Related Questions