Thursday 15 September 2011

android - AfterTextChanged and OnFocusChangedListener -



android - AfterTextChanged and OnFocusChangedListener -

i've got textwatcher on multiple edittext boxes takes calculations , outputs result textview. however, need way utilize decimalformat after user types edittext, formats so: "$###,###,###.00". i've thought using onfocuschangedlistener, seems still trigger aftertextchanged event. how don't end stack overflow?

the textwatcher calls method this:

textwatcher watch = new textwatcher() { @override public void aftertextchanged(editable s) { calc(); } private void calc() { editable evalue1 = new.gettext(), evalue2 = ti.gettext(), evalue3 = acc.gettext(); double value1 = 0.0, value2 = 0.0, value3 = 0.0, result = 0.0; if (evalue1 != null) value1 = todouble(evalue1); if (evalue2 != null) value2 = todouble(evalue2); if (evalue3 != null) value3 = todouble(evalue3); if (value1 != null && value2 != null && value3 != null) result = value1 - (value2 + value3); td.settext(formatcur(result)); } private string formatcur(double result) { decimalformat df = new decimalformat("$###,###,###.00"); string format = df.format(result); homecoming format; }

did seek removing listener, setting text, adding listener again?

android android-edittext textwatcher onfocus

No comments:

Post a Comment