【问题标题】:Kotlin Spinner OnItemSelected IntentKotlin Spinner OnItemSelected 意图
【发布时间】:2021-10-16 14:34:56
【问题描述】:

大家好,我创建了一个包含三个选项的微调器。现在我希望用户决定一个选项。然后用户应该被引导到拟合活动。但是通过将 Intent 方法添加到所选的 on Item 时出现错误。所以它“不知道”函数类型

option.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
            override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
                result.text = options.get(p2)
                if (options.get(p2) == "3 Rounds") {
                    val intent = Intent(this, Settings::class.java)
                    startActivity(intent)
                }
            }

            override fun onNothingSelected(p0: AdapterView<*>?) {
                result.text = "Please Select"
            }
        }

当我按 Alt + Enter 时,它只是说要创建一个函数。

【问题讨论】:

  • val intent = Intent(this@YourActivity, Settings::class.java) 试试这个
  • 谢谢它的工作
  • 另外,检查答案并接受它。因为它对他人也有帮助

标签: android kotlin android-intent


【解决方案1】:

在 Kotlin 中,您必须在 this 关键字之后提及您的 Activity 名称,然后是 @

val intent = Intent(this@YourActivity, Settings::class.java)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2011-08-03
    • 1970-01-01
    相关资源
    最近更新 更多