0

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?

Denis Zavedeev
  • 7,627
  • 4
  • 32
  • 53
Blue
  • 1,408
  • 4
  • 17
  • 36
  • 1
    I'm wondering if this is an XY problem, because I don't see what use obsolete variables would be when debugging a click listener that cannot access them anyway. – Tenfour04 Sep 25 '19 at 19:23
  • You can write `val e = e` inside the `onClickListener` and you will see it. – EpicPandaForce Dec 14 '19 at 14:29

1 Answers1

3

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.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245