D
D
den_kvlchk2021-04-11 08:32:23
Java
den_kvlchk, 2021-04-11 08:32:23

How to manage variables with android buttons?

I have an application where there are many buttons on one activity, I need a variable to be saved after clicking on each, that is, I have 4 rows horizontally and each row has 9 buttons (from 1 to 9) for each button via cwich a variable is set example:

switch (v.getId()) {
            case R.id.ps0: a = 0;
                break;
            case R.id.ps1: a = 1;
                break;
            case R.id.ps2: a = 2; //и так до 9
           case R.id.vs0: b = 0;
                break;
            case R.id.vs1: b = 1;
                break;
            case R.id.vs2: b = 2;
                break;
            case R.id.vs3: b = 3;
                break;
            case R.id.vs4: b = 4; // и соответственно третий ряд 
break;
case R.id.ts0: c = 0;
                break;
            case R.id.ts1: c = 1;
                break;
            case R.id.ts2: c = 2; //так соответственно тоже 9 кнопок
                break;

Actually, I have a formula by which these variables should be considered
result = (a*100+b*10+c*1)/100
textView.setText(result);

So the question is, how can I make all the data change independently of the others, that is, if I change the a button so that b and c do not change, respectively, if I press c, then a and b should not change?
A banal example if suddenly it is still not clearly explained, there is a = 2, b = 1, c = 5 and the formula d = a + b + c, that is, it turns out d = 8, suddenly one variable has changed, the rest have not changed yet, a = 8, respectively d = 15.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question