gpt4 book ai didi

android - 未设置 PlaceSelectionListener。不会传递任何结果

转载 作者:行者123 更新时间:2023-11-29 22:44:00 25 4
gpt4 key购买 nike

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

Places: No PlaceSelectionListener is set. No result will be delivered.

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}")
}
})

最佳答案

您正在使用已弃用的代码。尝试替换这一行:

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?

经过上述更改后,您的确切代码对我有效,所以我希望这对您有所帮助!

关于android - 未设置 PlaceSelectionListener。不会传递任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58727858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com