【问题标题】:Open different activities based on Spinner Selection - Kotlin根据 Spinner Selection 开启不同的活动 - Kotlin
【发布时间】:2020-07-06 06:50:00
【问题描述】:

我是 Kotlin 和 Android Studio 的新手,我正在尝试做一些我认为应该相当容易但我似乎无法做到的事情。

我有一个包含国家/地区的微调器。对于每个选择,我想打开相应的活动。我尝试了一个 If 语句,但我似乎只能传递一个字符串:

button.setOnClickListener {

        if (country == "France") {
            val intent = Intent(this, FranceSelect::class.java)
            startActivity(intent)
        } else if (country == "Spain") {
            val intent = Intent(this, SpainSelect::class.java)
            startActivity(intent)
        }
        val intent = Intent(this, CountrySelect::class.java)
        startActivity(intent)
    }

等等

如果我能得到任何帮助,我将不胜感激。

谢谢。

【问题讨论】:

  • 请发布您的代码

标签: android kotlin android-activity spinner


【解决方案1】:

我想我明白了。我的字符串周围缺少括号。

我现在拥有它

button.setOnClickListener { 
if (country == ("France")) 
{ val intent = Intent(this, FranceSelect::class.java) 
startActivity(intent) } 
else if (country == ("Spain")) 
{ val intent = Intent(this, SpainSelect::class.java)
 startActivity(intent) } 
} 

似乎enter code heres 已经解决了这个问题。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    相关资源
    最近更新 更多