android - EditText Removing Currency Symbol in TextWatcher not working -


i want remove dollar sign amount formatter not working assigned replace it contains dollar sign. how can this?

here code text watcher.

numberformat canadaenglish = numberformat.getcurrencyinstance(locale.canada);         public class moneytextwatcher implements textwatcher {         private final weakreference<edittext> edittextweakreference;         boolean hasfractionalpart = false;         private edittext edittext;          public moneytextwatcher(edittext edittext) {             edittextweakreference = new weakreference<edittext>(edittext);             this.edittext = edittext;         }          @override         public void beforetextchanged(charsequence s, int start, int count,                 int after) {         }          @override         public void ontextchanged(charsequence s, int start, int before,                 int count) {             if (s.tostring().contains(string.valueof(df.getdecimalformatsymbols().getdecimalseparator()))) {                 hasfractionalpart = true;             } else {                 hasfractionalpart = false;             }             if (misinwatcher)                 return;             misinwatcher = true;         }          @override         public void aftertextchanged(editable editable) {             if (edittext == null)                 return;             string s = editable.tostring();             edittext.removetextchangedlistener(this);             string cleanstring = s.tostring().replaceall("[$,.]", "");             string formatted = "";             system.out.println(cleanstring);                  bigdecimal parsed = new bigdecimal(cleanstring).setscale(2,bigdecimal.round_floor).divide(new bigdecimal(100),bigdecimal.round_floor);                 formatted = canadaenglish.format(parsed).replace("\\$",pesocurrency);                 system.out.println("formatted > " + formatted);                 string trimformatted = formatted.replace("\\$", pesocurrency);                 system.out.println("trimformatted > " + trimformatted);                 edittext.settext(formatted.replace("\\$", ""));                 edittext.setselection(formatted.length());             edittext.addtextchangedlistener(this);          }     } 

try this:

string chartoreplace = new string[]{"[","$",",",".","]"};  for(string s: chartoreplace)     cleanstring = cleanstring .replace(s,""); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -