How to work with multiple EditText using addTextChangedListener in android

I have 3 EditText named editTextA , editTextB and editTextC . What I want to do is when text changes on either one of the EditTexts, the other two to update.

It is working correctly with single addTextChangedListener for editTextA and updating editTextB. But when I add another addTextChangedListener to editTextB, it is not working. My app crashed. I used hasfocus() method to find that which EditText is currently focused but same result.

Upvotes: 1

Views: 79

Answers (2)

A. Badakhshan
A. Badakhshan

Reputation: 1043

While I'm agree with Mahdi-bagvand, I had same problem and you need to put an ending condition. For example for me it was the length of one EditText. Without putting an ending condition this will be an infinite loop and your app will crash.

Upvotes: 0

Mahdi-bagvand
Mahdi-bagvand

Reputation: 1407

you problem is infinite loop.

  1. EditTextA changes
  2. onTextChanged A called.
  3. change text of EditTextB
  4. onTextChanged B called.
  5. change text of EditTextA
  6. Goto 2

Upvotes: 1

Related Questions