未设置PlaceSelectionListener。没有结果将被交付

当我单击autocompletefragment时。日志显示:

  

位置:未设置PlaceSelectionListener。没有结果   已交付。

val realView = inflater.inflate(R.layout.fragment_connect,container,false)

Places.initialize(activity!!.applicationContext,getString(R.string.google_maps_key))
val placesClient = Places.createclient(activity!!)

val autocompleteFragment1 = fragmentManager?.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?'

autocompleteFragment1?.setCountry("PH")
// Specify the types of place data to return.
autocompleteFragment1?.setPlaceFields(listOf(Place.Field.ID,Place.Field.NAME))

// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment1?.setOnPlaceSelectedListener(object : PlaceSelectionListener {
    override fun onPlaceSelected(place: Place) {
        Log.d("Hey",place.toString())
    }

    override fun onError(status: Status) {
        // TODO: Handle the error.
        Log.d("HOY","An error occurred: ${status.statusCode}")
    }
})
o919977230 回答:未设置PlaceSelectionListener。没有结果将被交付

您正在使用不建议使用的代码。尝试替换此行:

val autocompleteFragment1 = fragmentManager?.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?'

有了这个:

val autocompleteFragment1 = supportFragmentManager.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?

完成上述更改后,您的确切代码将对我有效,所以希望对您有所帮助!

本文链接:https://www.f2er.com/3153157.html

大家都在问