0

I know there are some questions like this , but none of the answers could solve my problem. So I'm gonna ask myself. How can I solve this problem? Sorry for don't specify more, I'm starting codingenter image description here

3 Answers3

0

A way of solving the problem would be to make the variable score1 a field variable, so after the declaration of the java class make a variable with private visibility and then increment that variable.

 public class Test{
    private int score1;
    //Constructor for the class for setting the variable.
    public Test(){
    score1 = 0 //Whatever the start value should be
    }
  }

All in all you now have a variable which can be "seen" from the inner class of the actionlistener.

Hope that helps :)

Mark
  • 41
  • 6
0

replace

int score1=sharedPreferences.getInt("score",DEFAULT);

with

final int score1=sharedPreferences.getInt("score",DEFAULT);

or instead you declare score as a class variable

public class someclass{
 int score1;
 //here comes the rest of the code
}

good luck

-1

Declare score1 as a class attribute.

Birk
  • 126
  • 1
  • 2
  • 9