gpt4 book ai didi

java - 尝试声明 BottomNavigationView

转载 作者:行者123 更新时间:2023-12-01 23:23:09 26 4
gpt4 key购买 nike

我是 Kotlin 开发新手。我正在尝试执行 BottomNavigationView,一切正常,但是当我想为 ItemSelected Listener 创建 BottomNavigationView 变量时,出现以下错误:

Function invocation 'BottomNavigationView(...)' expected.

但在我的教程中它是这样声明的:BottomNavigationView BottomNav

怎么了,我不明白..你能帮我一下吗?

最佳答案

为bottomViewListener声明一个全局变量

'onNavigationItemSelectedListener'

在onCreate()中初始化并设置bottomView中的监听器

val navView: BottomNavigationView = findViewById(R.id.nav_view) navView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener)

private val onNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
return@OnNavigationItemSelectedListener true
}
R.id.navigation_deals -> {
return@OnNavigationItemSelectedListener true
}

}
false
}

关于java - 尝试声明 BottomNavigationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58320441/

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