My requirement is as follows: I need to get the data from multiple text
boxes (EditText) and I need to calculate and show it in the another
EditText. How it is possible? As I mentioned there is no button to
press automatically it needs to appear in the total box.
I referred this, but after the loop I’m not getting the value I
declared the variable globally but also not getting the value of the
text box.
EditText et1, et2, etTot;
int x, y, tot;
et1 = (EditText) findViewbyId(R.id.edittext1);
et2 = (EditText) findViewbyId(R.id.edittext2);
etTot = (EditText) findViewbyId(R.id.edittextTot);
et1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
x = Integer.parseInt(et1.getText().toString().trim());
System.out
.println("AMOUNT IS " + et1.getText().toString());
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
}
});
//same as for et2......
tot = x + y;
etTot.setText(tot.toString());
1 Answer