Android Studio变量未出现在OnClickListener主体中 [英] Android Studio Variables not appearing in OnClickListener body
问题描述
我正在使用调试器在android studio中工作.
I'm working in android studio using the debugger.
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
的行中在调试器中设置断点,我会看到loginButton
和emailInput
输出到调试器的变量部分.但是,如果我将调试器放置在loginButton.setOnClickListener
内,它们将不再显示.
If I set a breakpoint in the debugger at the line containing var e = 2
I will see loginButton
and emailInput
output to the variable section of the debugger. But if I place the debugger inside of loginButton.setOnClickListener
they no longer appear.
点击后,我希望能够看到变量.我该怎么办?
I would like to be able to see variables after the click has occurred. What can I do?
推荐答案
在单击侦听器中,这些变量超出范围,新的执行范围成为匿名类.
Within the click listener, those variables are out of scope and the new scope of execution becomes the anonymous class.
如果您仍要检查视图,则应将它们声明为Activity类中的字段.
If you would like to still inspect the views, then you should declare them as fields within the Activity class.
这篇关于Android Studio变量未出现在OnClickListener主体中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!