问题
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.)
}
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?
回答1:
Within the click listener, those variables are out of scope and the new scope of execution becomes the anonymous class.
If you would like to still inspect the views, then you should declare them as fields within the Activity class.
来源:https://stackoverflow.com/questions/58105131/android-studio-variables-not-appearing-in-onclicklistener-body