【问题标题】:How can I programatically hide or suppress the search suggestions list?如何以编程方式隐藏或禁止搜索建议列表?
【发布时间】:2012-10-26 13:08:18
【问题描述】:
如何以编程方式隐藏SearchView下方弹出的建议列表?
有时我希望SearchView 不被inconified 并且没有焦点。我可以分别使用setIconified(false) 和clearFocus() 方法来做到这一点,但如果SearchView 中有任何文本,它将显示搜索建议列表,我需要隐藏/禁止它。
【问题讨论】:
标签:
java
android
android-searchmanager
【解决方案1】:
searchView.setSuggestionsAdapter(null); 为我做了这个伎俩。
【解决方案2】:
尝试将OnQueryTextListener 设置为您的搜索视图,并在您不希望显示任何建议时在onQueryTextChange 上返回true。
【解决方案3】:
如果您在SearchView 上设置了SearchView.OnQueryTextListener,则可以在onQueryTextSubmit 中返回false。
这将确保无论何时用户提交搜索查询(通过点击建议或键盘上的“搜索”按钮),建议都会关闭/隐藏。