if I have set text in textview in such way, which is not problem:
tv.setText("" + ANS[i]);
this simply getting from this way.
String a = tv.getText().toString();
int A = Integer.parseInt(a);
But in case of setting value in textView.
tv1.setText(" " + X[i] + "\n" + "+" + " " + Y[i]);
which is like this
5
+9
I have problem , this value how to get.
I haven’t tested this – but it should give you a general idea of the direction you need to take.
For this to work, I’m going to assume a few things about the text of the
TextView:TextViewconsists of lines delimited with"\n".TextViewwhich will all include one operator and one number.Charof a line.First we get the text:
Then we split it up for each line:
Now we need to calculate the total value:
The method calculate should look like this, assuming that we know the first
Charof a line is the operator:EDIT
So the above as stated in the comment below does “left-to-right” calculation, ignoring the normal order ( + and / before + and -).
The following does the calculation the right way:
The method
getValueis a recursive method and it should look like this:Special cases that the recursive method does not handle:
Also the fact the we’re using
Integersmight give some “odd” results in some cases as e.g. 5/3 = 1.