This also for changing alternate editText value after change TextWatcher in Andorid.

Or This Error:- java.lang.stackoverflowerror stack size 8mb edittext aftertextchanged.

try this :-

public class MainActivity extends AppCompatActivity 
implements TextWatcher{

   EditText editText1, editText2;
   @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       editText1 = findViewById(R.id.editText1);
       editText2 = findViewById(R.id.editText2);

       editText1.addTextChangedListener(this);
       editText2.addTextChangedListener(this);

      }

    @Override
    public void beforeTextChanged(CharSequence s, int start, 
           int 
           count, int after) {

    }

   @Override
   public void onTextChanged(CharSequence s, int start, int 
           before, int count) {

   }

  @Override
  public void afterTextChanged(Editable s) {

      if (getCurrentFocus() == editText1) {
         // is only executed if the EditText was directly 
            changed by the user.
          Log.e("check","getCurrentFocus() == editText1");

          editText2.removeTextChangedListener(this);

          editText2.setText(String.valueOf(s));

          editText2.addTextChangedListener(this);

       //            editText1.clearFocus();
      }

      if (getCurrentFocus() == editText2) {
          // is only executed if the EditText was directly 
             changed by the user
          Log.e("check","getCurrentFocus() == editText2");

          editText1.removeTextChangedListener(this);

          editText1.setText(String.valueOf(s));

          editText1.addTextChangedListener(this);

        //            editText2.clearFocus();
        }


   }

}

Comments

Popular posts from this blog

Android Studio 3.5 or above usb device not detected in Android Studio or Unable to detect adb version, exit value: 0xc0000135. ADB depends on the Windows Universal C Runtime, which is usually installed by default via Windows Update. You may need to manually fetch and install the runtime package here: https://support.microsoft.com/en-ca/help/2999226/update-for-universal-c-runtime-in-windows

Lint found fatal errors while assembling a release target.

ViewModelProviders.of(this) is deprecated what to use instead ViewModelProviders.of(this) OR if you don't want to use ViewmodelFactory OR ViewModelProviders error.