Jacek Jacek - 1 year ago 72
Android Question

Hide keyboard when AutoComplateTextView item clicked

I'm trying to hide software kayboard when user click on AutoComplateTextView item, but it doesn't work.

This is my code:

mAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
* do something
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromInputMethod(mAutoCompleteTextView.getWindowToken(), 0);

Answer Source

put this code in the onClick method:

    InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    View v = getActivity().getCurrentFocus();

    if (v != null) {


        inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download