类型不匹配:推断类型是 `<no name provided>` 但 SearchView.OnQueryTextListener!是预料之中的

问题描述 投票:0回答:1
I'm working on a Weather App in Kotlin and encountering an issue with the SearchView.OnQueryTextListener     implementation. I've followed a tutorial on YouTube, and while most of my code works perfectly, I'm having     trouble with the city search functionality. Here's my code:
private fun searchCityFunction() {
val searchView = binding.searchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
    override fun onQueryTextSubmit(query: String?): Boolean {
        if (query != null) {
            fetchWeatherData(query)
        }
        return true
    }

    override fun onQueryTextChange(newText: String?): Boolean {
        return true
    }
})
}

我多次检查了我的代码,并将其与 YouTube 教程进行了比较,但我无法识别错误。当我尝试添加城市选项时,出现错误。我也尝试向 ChatGPT 寻求帮助,但没有成功。

任何人都可以帮助我识别并解决我的 SearchView.OnQueryTextListener 实现的问题吗?任何见解或建议将不胜感激。

kotlin android-studio weather-api
1个回答
0
投票

绑定.搜索。 setOnQueryTextListener(对象: 搜索视图。 OnQueryTextListener , 安卓 。小部件。搜索视图。 OnQueryTextListener

© www.soinside.com 2019 - 2024. All rights reserved.