Search code examples
androidsearchview

How do I capture action button back from SearchView?


how can I capture the back arrow command in Android SearchView.

need to hide the previously opened list


Solution

  • You can use setOnActionExpandListener of MenuItem

    mSearchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    return true;
                }
    
                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    //TODO Here you can do your list hiding stuff :D
                    return true;
                }
            });