Android Studio 变量未出现在 OnClickListener 正文中

Android Studio Variables not appearing in OnClickListener body

我在 android 工作室使用调试器工作。

var loginButton = findViewById<Button>(R.id.loginButtonFinal)
var emailInput = findViewById<EditText>(R.id.emailInput)
var e = 2
loginButton.setOnClickListener {
    println("Log In Button pressed, will log in now")
    //            insert code for login in here
    //            signIn(email = emailInput.)
}

如果我在包含 var e = 2 的行中的调试器中设置断点,我将看到 loginButtonemailInput 输出到调试器的变量部分。但是,如果我将调试器放在 loginButton.setOnClickListener 内,它们将不再出现。

我希望能够在点击发生后看到变量。我能做什么?

在点击侦听器中,这些变量超出范围,新的执行范围变为匿名 class。

如果您仍想检查视图,则应将它们声明为 Activity class 中的字段。