android - Kotlin - 未调用 google 的 Place Autocomplete API onClick 的清除按钮侦听器
问题描述
我正在尝试为来自谷歌的 Place Autocomplete API 的清除按钮创建一个侦听器。clearButton()
我在片段的方法中调用了我的onViewCreated
方法
清除按钮()
placeAutocompleteFragment?.view?.findViewById<View>(R.id.place_autocomplete_clear_button)
?.setOnClickListener {
View.OnClickListener {
Log.d(TAG, "Cleared")
it?.findViewById<EditText>(R.id.place_autocomplete_search_input)?.setText("")
it?.visibility = View.GONE
}
}
现在,当我单击清除按钮图标时,文本不会被删除,没有任何反应。我仍然可以输入一个新的位置,但我无法清除它。我Log.d
的也没有显示。
解决方案
弄清楚了。我把方法调用设置错了。
它应该是这样的:
private fun clearButton() {
placeAutocompleteFragment?.view?.findViewById<View>(R.id.place_autocomplete_clear_button)?.setOnClickListener {
Log.d(TAG, "Cleared Button Clicked")
it.visibility = View.GONE
//do something
}
}
推荐阅读
- python - 我已经完成了代码,但是我不明白出了什么问题
- json - 使用 circe 在类主体中解码带有 `require` 的案例类会引发异常而不是返回 `Left`
- javascript - Mapbox 脚本到 html
- autodesk-forge - 如何保留 Viewer Toolbar 之前的状态
- reactjs - 在 next.js 中使用 jest 导入时找不到模块错误
- html - 将元素高度设置为跟随显示 flex 行中的兄弟高度
- apache - 如何在 htaccess 中重写 url
- python - If 语句未按预期运行
- latex - 在行中的段落中过度\hbox(1.38991pt太宽),即使正在生成PDF,也会发出乳胶警告
- python - 如何计算 collection.defaultdict 值?