Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide keyboard when a search is submitted or a search suggestion is chosen

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.

like image 957
Mridang Agarwalla Avatar asked Sep 08 '12 13:09

Mridang Agarwalla


People also ask

How do I hide the keyboard on my Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field. This will force the keyboard to be hidden in all situations.


1 Answers

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.

like image 66
CommonsWare Avatar answered Oct 19 '22 12:10

CommonsWare