Hide keyboard when a search is submitted or a search suggestion is chosen
Asked Answered
H

2

5

I have a action bar search widget that offers search suggestion too. When the user types in a query and submits it or chooses a search suggestion, the keyboard doesn't disappear. How can I resolve this issue?

I haven't been able to figure out how to hide the keyboard upon search submit or suggestion choose.

Thank you.

Hose answered 8/9, 2012 at 13:7 Comment(1)
possible duplicate of Close/hide the Android Soft KeyboardHose
A
9

To hide the input method editor, use InputMethodManager:

  InputMethodManager imm=
      (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);

  imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

You can use this from onEditorAction(), for example, as shown in this sample project.

Agateware answered 8/9, 2012 at 13:11 Comment(0)
S
2

I have just face to the same problem, and this way to hide keyboard after search

  @Override
 public boolean onQueryTextSubmit(String query) {
   searchView.clearFocus();
 return true;

}

GoodLuck !!

Shoshone answered 21/7, 2015 at 4:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.