I have three Edittext.when i change first Edittext value,third Edittext value will change by Textwatcher.when i change third Edittext ,first edittext value will change by Textwatcher.App is crasing when i run the code.
Here is my code
   qty = (EditText) findViewById(R.id.qty);
   rate = (EditText) findViewById(R.id.rate);
   amount = (EditText) findViewById(R.id.amount);
   qty.addTextChangedListener(new TextWatcher() {
       @Override
       public void onTextChanged(CharSequence s, int start, int before, int count) { 
           // TODO Auto-generated method stub
       }
       @Override
       public void beforeTextChanged(CharSequence s, int start, int count, int after) {
           // TODO Auto-generated method stub
       }
       @Override
       public void afterTextChanged(Editable s) {
           // TODO Auto-generated method stub
           String qtyvalue = qty.getText().toString();
           String ratevalue = rate.getText().toString();
           if (qtyvalue.equals("") || ratevalue.equals("")) {
               val1 = 0d;
               val2 = 0d;
           } else {
               val1 = Double.parseDouble(qtyvalue);
               val2 = Double.parseDouble(ratevalue);
           }
           amount.setText(Double.toString(val1 * val2));
       }
   });
   amount.addTextChangedListener(new TextWatcher() {
       @Override
       public void onTextChanged(CharSequence s, int start, int before, int count) {
           // TODO Auto-generated method stub
       }
       @Override
       public void beforeTextChanged(CharSequence s, int start, int count, int after) {
           // TODO Auto-generated method stub
       }
       @Override
       public void afterTextChanged(Editable s) {
           // TODO Auto-generated method stub
           String amountvalue = amount.getText().toString();
           String ratevalue = rate.getText().toString();
           if (amountvalue.equals("") || ratevalue.equals("")) {
               val3 = 0d;
               val4 = 0d;
            } else {
               val3 = Double.parseDouble(amountvalue);
               val4 = Double.parseDouble(ratevalue);
            }
            System.out.println(Double.toString((double)val3/val4));    
            qty.setText(Double.toString((double)val3/val4));
        }
    });
Logcat
 java.lang.StackOverflowError
            at android.text.method.ReplacementTransformationMethod$ReplacementCharSequence.getChars(ReplacementTransformationMethod.java:151)
            at android.text.TextUtils.getChars(TextUtils.java:78)
            at android.text.TextUtils.indexOf(TextUtils.java:111)
            at android.text.StaticLayout.generate(StaticLayout.java:209)
            at android.text.DynamicLayout.reflow(DynamicLayout.java:324)
            at android.text.DynamicLayout.<init>(DynamicLayout.java:174)
            at android.widget.TextView.makeSingleLayout(TextView.java:6964)
            at android.widget.TextView.makeNewLayout(TextView.java:6813)
            at android.widget.TextView.checkForRelayout(TextView.java:7409)
            at android.widget.TextView.setText(TextView.java:4300)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$1.afterTextChanged(Delivery.java:93)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$2.afterTextChanged(Delivery.java:127)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$1.afterTextChanged(Delivery.java:93)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$2.afterTextChanged(Delivery.java:127)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$1.afterTextChanged(Delivery.java:93)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$2.afterTextChanged(Delivery.java:127)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$1.afterTextChanged(Delivery.java:93)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$2.afterTextChanged(Delivery.java:127)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView.java:4137)
            at android.widget.EditText.setText(EditText.java:104)
            at android.widget.TextView.setText(TextView.java:4112)
            at com.example.admin.foms.Delivery$1.afterTextChanged(Delivery.java:93)
            at android.widget.TextView.sendAfterTextChanged(TextView.java:8293)
            at android.widget.TextView.setText(TextView.java:4307)
            at android.widget.TextView.setText(TextView
 
     
     
     
     
     
    