-2

In my project I have 7 EditText field. User will only need to fill their own value in first two EditText.

I need a series calculation like this...

  1. (after user input) subtract ed1-ed2 the result automatically show in ed3 field.

  2. multiply ed3*2 = result show in ed4 field automatically.

  3. multiply ed3*3= result will show in ed5 field.

  4. multiply ed3*4=result will show in ed6 field.

  5. Finally sum of ed4+ed5+ed6= result will show in ed7 field automatically.

So how to do it any one please help. Thank you in Advance.

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50

1 Answers1

1

All EditText use a same TextWatcher. A simple solution like this.

    EditText et1;
    EditText et2;
    TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            int num1 = Integer.valueOf(et1.getText().toString()); // Make sure you get a number
            int num2 = Integer.valueOf(et2.getText().toString());
            // do your calculation
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };
    et1.addTextChangedListener(textWatcher);
    et2.addTextChangedListener(textWatcher);
Rust Fisher
  • 331
  • 3
  • 12