Reputation: 51
I'm new to android, I made this simple app that adds 1 to a variable called clicks every time the user clicks the button. The first time I click the button it works perfectly, but when I click it other times it doesn't work at all. Here's my code: ```
val clicks = 0
button.setOnClickListener() {
tvn.setText("You clicked the button $clicks times.")
}
```
Upvotes: 0
Views: 68
Reputation: 51
I was using val
but not var
and that's why I couldn't change the value of the variable clicks
Upvotes: 2
Reputation: 1258
suppose clicks
is the private member of class
private int clicks = 0;
...............
button.setOnClickListener() {
clicks++;
tvn.setText("You clicked the button times."+ clicks);
}
Upvotes: 1