Hide keyboard after user searches?

Emil Davtyan picture Emil Davtyan · Mar 24, 2012 · Viewed 15.1k times · Source

I have an activity where there is an EditText and on enter key search results are shown, so what I simply want to do is to close the keyboard when search results are about to show to prevent the user from having to do it. However if the user wants to refine his search the keyboard should open back up if he taps into the EditText again.

This has been more difficult than I imagined, I've been search and tried a few things most don't even close the keyboard on my HTC, one method where the InputType is set to INPUT_NULL closes the keyboard but it doesn't open afterwards.

Any suggestions on how to do this?

Answer

dazito picture dazito · Jul 2, 2014
@Override
public boolean onQueryTextSubmit(String query) {
    // Your search methods

    searchView.clearFocus();
    return true;
}

Straight to the point and clean.