Luke Willmer
Luke Willmer

Reputation: 327

How to hide the on-screen keyboard when pressed enter/pressed one of google places predictions?

I've created an Android app that uses the Google Places AutoCompleteTextView which successfully lists the predictions. However, when a user has selected the prediction that they are looking for, the keyboard doesn't hide (Same for when a user presses enter or finish on the keyboard). How easy is to to hide the keyboard once a user has selected one of the Google predictions?

Upvotes: 0

Views: 70

Answers (1)

Luke Willmer
Luke Willmer

Reputation: 327

@DERPA_CHIEF You were correct! The code necessary to add was:

autoCompView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                  InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                  mgr.hideSoftInputFromWindow(autoCompView.getWindowToken(), 0);
              }
            });

Upvotes: 1

Related Questions