0

Google SupportPlaceAutocompleteFragment has listener when address in fragment is selected with: autocompleteFragment.setOnPlaceSelectedListener

But it works only when results overlay is closed and you deal with that results. My goal is to intercept click on result on earlier stage.

What I want to do is stay on the page with autocomplete fragment and instead of closing it continue entering address. For example, autocomplete fragment suggests me street, and I want to autocomplete it and give user a chance to specify house.

Possible solution is to get place predictions programmatically and handle all UI by my own, but was hoping for an easier way.

1 Answers1

0

Quite dirty, but working solution.

If place type is route - call place autocomplete fragment again

autocompleteFragment.setOnPlaceSelectedListener(object : PlaceSelectionListener {
        override fun onPlaceSelected(place: Place) {
            if (place.placeTypes.first() == Place.TYPE_ROUTE) {
                autocompleteFragment.view?.findViewById<EditText>(R.id.place_autocomplete_search_input)?.performClick()
            }
        }

        override fun onError(status: Status) {
            error("An error occurred: $status")
        }
    })