android - StackOverflowError - Redundant call onTextChanged -


(i'm learning english... therefore, forgive me)

i'm making app convert bin, dec , hex. have 3 edittext (number type) , want when 1 of tree contents have changed.

my 3 edittext:

<edittext     android:id="@+id/input1"     android:inputtype="number"     android:digits="01"     android:hint="bin"     android:layout_width="match_parent"     android:layout_height="wrap_content"/>  <edittext     android:id="@+id/input2"     android:inputtype="number"     android:digits="0123456789"     android:hint="dec"     android:layout_width="match_parent"     android:layout_height="wrap_content"/>  <edittext     android:id="@+id/input3"     android:digits="0123456789abcdefabcdef"     android:hint="hex"     android:layout_width="match_parent"     android:layout_height="wrap_content"/> 

so used following code handle text changes:

edittext input1 = (edittext) findviewbyid(r.id.input1); edittext input2 = (edittext) findviewbyid(r.id.input2); edittext input3 = (edittext) findviewbyid(r.id.input3);  input1.addtextchangedlistener(new textwatcher() {          public void beforetextchanged(charsequence s, int start, int count, int after) {}          public void ontextchanged(charsequence s, int start, int before, int count) {              string bin = input1.gettext().tostring();             string s1 = bintodec(bin) + "";             string s2 = bintohex(bin);             input2.settext(s1);             input3.settext(s2);         }          public void aftertextchanged(editable s) {}     });      input2.addtextchangedlistener(new textwatcher() {          public void beforetextchanged(charsequence s, int start, int count, int after) {}          public void ontextchanged(charsequence s, int start, int before, int count) {             try{                 string dec = input2.gettext().tostring();                 int num = integer.parseint(dec);                  input1.settext(dectobin(num));                 input3.settext(dectohex(num));             }             catch (numberformatexception nfe){              }         }          public void aftertextchanged(editable s) {}     });      input3.addtextchangedlistener(new textwatcher() {          public void beforetextchanged(charsequence s, int start, int count, int after) {}          public void ontextchanged(charsequence s, int start, int before, int count) {              string hex = input3.gettext().tostring();             input1.settext(hextobin(hex));             input2.settext(hextodec(hex) + "");         }          public void aftertextchanged(editable s) {}     }); 

but... everytime user types in edittext 1, example, content of edittext 2 , 3 change. causes call ontextchanged , infinity stack of call (stackoverflow). so... there better way want? can me, please? thank you!!!

instead of using textchangedlistener, recommend having button press once user done inputting text. eliminates infinite calls ontextchange. button can check 1 user entered numbers , can change other edittexts accordingly.


Comments