Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely collapse a SearchView after an item selected?

I've been struggling with this for weeks.. I have a global search that offers up a custom listview with suggestions as a user types. When a user selects an option, I want the searchview to return to its completely collapsed state.

enter image description here

Instead, it shrinks down but stays in a slightly expanded view.

enter image description here

I've thrown EVERYTHING I can find at this thing to close it, but cannot for the life of me get the right method. Here's the function:

    final SearchView.OnCloseListener closeListener = new SearchView.OnCloseListener() {          @Override         public boolean onClose() {             return closeSearch();         }     };      protected boolean closeSearch() {     _searchView.clearFocus();     _searchView.setQuery("", false);     _searchView.setFocusable(false);     _searchMenuItem.collapseActionView();     isSearchFragmentVisible(false);     return false; } 

Close search is then manually called when an item is selected from the custom "suggestion" listview.

like image 252
Sebastian Avatar asked Nov 28 '12 20:11

Sebastian


1 Answers

Instead of calling _searchView.onActionViewCollapsed() call menuItem.collapseActionView() where _searchView = menuItem.getActionView().

like image 171
siavach Avatar answered Oct 02 '22 22:10

siavach