gpt4 book ai didi

kotlin - 在Kotlin中转到菜单项选择上的另一个事件

转载 作者:行者123 更新时间:2023-12-02 12:53:46 24 4
gpt4 key购买 nike

我的应用程序的工具栏中添加了“选项”菜单项“选定”。我想在单击项目时添加 Action ,甚至转到其他 Activity 。 l Intent但不起作用

override fun onOptionsItemSelected(item: MenuItem): {

when (item.itemId) {
R.id.flightarrbeforbgw ->
Intent intent = new Intent(this, FlightsArrivelBeforBGW.class);
this.startActivity(intent)

else ->
return null
}
}

最佳答案

您的意图格式不正确。这是应该的样子:

Intent (this, YourActivity::class.java)

因此,您的代码应如下所示:
when (item.itemId) {
R.id.flightarrbeforbgw ->{
this.startActivity(Intent(this,FlightsArrivelBeforBGW::class.java))
return true
}
else -> super.onOptionsItemSelected(item)
}

关于kotlin - 在Kotlin中转到菜单项选择上的另一个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53582783/

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