android - How format content of EditText in afterTextChanged? -
txt1.addtextchangedlistener(new textwatcher() { public void ontextchanged(charsequence s, int start, int before, int count) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void aftertextchanged(editable s) { string value = txt1.gettext().tostring(); txt1.settext(string.valueof(utilities .roundonedecimals(double.parsedouble(value)))); } });
if set text agian in [aftertextchanged] , program call event again.
how format content of edittext in aftertextchanged?
like @bojan kseneman suggestion, boolean
flag solve problem.
boolean enablechangelistener = true; txt1.addtextchangedlistener(new textwatcher() { public void ontextchanged(charsequence s, int start, int before, int count) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void aftertextchanged(editable s) { if(enablechangelistener){ enablechangelistener = false; string value = txt1.gettext().tostring(); txt1.settext(string.valueof(utilities .roundonedecimals(double.parsedouble(value)))); } } });
Comments
Post a Comment