'How can I get the previous Value of the TextView F12

How can I get the previous Value of the TextView F12? I want to put a Value in F12 and in a second Part, I want to add the previous Value with a new Value.

final String numbers = bundle.getString("numbers");         
int F12Total = 0;
F12.setText(String.valueOf(numbers));

    if (numbers != null){

        int num1 = Integer.parseInt(numbers.toString());
        int num2 = Integer.parseInt(F12.getText().toString());
        F12Total = num1 + num2;
        F12.setText(String.valueOf(F12Total));
    }


Solution 1:[1]

Create a String to use to temporarily store the value from F12 like so:

String valueOfF12 = F12.getText().toString();

and then refer back to that string when you need to retrieve that information later.

Solution 2:[2]

Store your TextView F12 value into a temporary tempF12 variable and use later.

Try this:

// Global
String tempF12 = "0";

...........
.................

final String numbers = bundle.getString("numbers");         

int F12Total = 0;
F12.setText(String.valueOf(numbers));

if (numbers != null) {

    int num1 = Integer.parseInt(numbers.toString());
    int num2 = Integer.parseInt(tempF12);

    F12Total = num1 + num2;
    F12.setText(String.valueOf(F12Total));
}

// Store current F12 value to use later
tempF12 = F12.getText().toString();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carl Poole
Solution 2 Ferdous Ahamed