0

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

user2340612
  • 10,053
  • 4
  • 41
  • 66

2 Answers2

1

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!

bmat
  • 2,084
  • 18
  • 24
  • I am currently using a SearchView into the ActionBar. Do you know if is it possible to add this feature to the SearchView widget? – user2340612 Oct 30 '14 at 21:18
  • @user2340612 according to the docs, it looks to be possible, although it's much more involved. I've updated my answer to include the relevant documentation for setting up this functionality. – bmat Oct 30 '14 at 22:28
1

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

user2340612
  • 10,053
  • 4
  • 41
  • 66