How can I programatically hide the list of suggestions that pops up up below the SearchView?

There are times when I'd like the SearchView to not be inconified and to not have focus. I can do this both using the setIconified(false) and the clearFocus() methods respectively, but if the SearchView has any text in it, it will display the list of a search suggestions and I need to hide/suppress that.

有帮助吗?

解决方案

Try to set an OnQueryTextListener to your search view, and return true on onQueryTextChange when you don't want any suggestions to show up.

其他提示

searchView.setSuggestionsAdapter(null); did that trick for me.

If you've set a SearchView.OnQueryTextListener on your SearchView, you can return false in onQueryTextSubmit.

This will make sure suggestions get closed/hidden whenever the user submits the search query (by clicking on a suggestion or the "search" button on the keyboard).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top