java - Wrong format of string in EditText with mask -


i trying setup edittext weight input. problem should format wegiht "1,149" maxlenght=5 (it's variable) , it's working untill press backspace. it's making "1,,49".

for example:

  • 1,2,3,4
  • backspace, backspace
  • 3,4

give me result:

  • 1,234
  • 1,2
  • 1,,23

            edittext.setfilters(new inputfilter[] {new inputfilter.lengthfilter(maxlenght)});          edittext.addtextchangedlistener(new textwatcher() {              @override             public void aftertextchanged(editable s) {                 try {                         edittext.removetextchangedlistener(this);                          string str = s.tostring();                         str = new stringbuilder(str).reverse().tostring().replaceall("(\\d{"+dokladnosc+"})", "$1,");                         str = new stringbuilder(str).reverse().tostring().replaceall("^,|,$", "");                         edittext.settext(str);                         try{                             //log.i("inf", edittext.length()+"-"+str.length());                             if(edittext.length() == str.length())                             {                                 edittext.setselection(str.length());                             }                             else                             {                                 edittext.setselection(str.length()-1);                             }                         }                         catch(exception exc)                         {                             log.e("err", exc.tostring());                             //edittext.setselection(str.length()-1);                         }                         edittext.addtextchangedlistener(this);                 } catch (numberformatexception e) {                     e.printstacktrace();                 }             } 

device test steps understand problem


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -