Abdul Salam
Abdul Salam

Reputation: 83

keyboard doesn't hide on back arrow click on Autocomplete(GooglePlacesPicker)

enter image description here

List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.LAT_LNG, Place.Field.ADDRESS, Place.Field.NAME);
    // Start the autocomplete intent.
    Intent intent = null;

    if (initialQuery != null && !initialQuery.isEmpty()) {
        intent = new Autocomplete.IntentBuilder(
                AutocompleteActivityMode.FULLSCREEN, fields).
                setInitialQuery(initialQuery).
                setTypeFilter(TypeFilter.CITIES).
                build(activity);
    } else {
        intent = new Autocomplete.IntentBuilder(
                AutocompleteActivityMode.FULLSCREEN, fields).
                setTypeFilter(TypeFilter.CITIES).
                build(activity);
    }

    activity.startActivityForResult(intent, GOOGLE_PLACES_PICKER_REQUEST_CODE);

The above code opens GooglePlacesPicker where we can search place. Tapping back arrow should close keyboard. but it doesn't.

I tried below method to close keyboard

   public static void hide(Context context) {
    try {
        if (context != null) {
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            if (((Activity) context).getCurrentFocus() != null) {
                View currentFocus = ((Activity) context).getCurrentFocus();
                if (currentFocus.getWindowToken() != null) {
                    imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.SHOW_FORCED);
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

but didn't worked. kindly help

Upvotes: 0

Views: 541

Answers (1)

sparkle ramani
sparkle ramani

Reputation: 130

set dismiss keyboard button like this

hideButton.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {

                        InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        in.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), 0);
                    }
    });

Upvotes: 1

Related Questions