I currently have a SearchView in the action bar of my application. When I click the search icon, the SearchView expands and the keyboard appears as expected. Pressing the “X” in the SearchView window closes the SearchView as expected. However, when SearchView is activated and I press the back button, my application terminates. This is the correct behavior, but now I'm trying to take a picture with the click of a button and just close the SearchView application (not my application) when SearchView is visible. Is there a way to call SearchView OnCloseListener () programmatically by pressing the back button? For example, something like this:
// On a back button press, if we are currently searching, // close the SearchView. Otherwise, invoke normal back button // behavior. public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (isSearchViewVisible) { SearchView searchView = (SearchView) menu.findItem(R.id.searchBox) .getActionView(); // This method does not exist searchView.invokeClose(); return true; } } return super.onKeyDown(keyCode, event); }
android searchview
Tim Jul 06 '13 at 19:15 2013-07-06 19:15
source share