Class Mywatcher implements Textwatcher {int beforetextlength = 0;int Ontextlength = 0;boolean ischanged = False;int Locati On = 0;//record cursor position private char[] tempchar;private stringbuffer buffer = new StringBuffer (); int konggenumberb = 0; @Overridep ublic void OnTextChanged (charsequence s, int start, int before,int count) {//TODO auto-generated method Stubontextlength = S.length (); Buffer.append (s.tostring ()); if (ontextlength = = Beforetextlength | | ontextlength <= 3| | isChanged) { ischanged = False;return;} Ischanged = true;} @Overridepublic void Beforetextchanged (charsequence s, int start, int count,int after) {//TODO auto-generated method stub Beforetextlength = S.length (); if (Buffer.length () > 0) {buffer.delete (0, Buffer.length ());} Konggenumberb = 0;for (int i = 0; i < s.length (); i++) {if (S.charat (i) = = ') {konggenumberb++;}}} @Overridepublic void aftertextchanged (Editable s) {//TODO auto-generated method stubif (ischanged) {location = Etaccount. Getselectionend (); int index = 0;WHile (Index < Buffer.length ()) {if (Buffer.charat (index) = = ") {Buffer.deletecharat (index);} else {index++;}} index = 0;int Konggenumberc = 0;while (Index < Buffer.length ()) {if (index = = 4 | | index = = 9 | | index = = | | | index = =) {Buffer.insert (index, '); konggenumberc++;} index++;} if (Konggenumberc > Konggenumberb) {location + = (konggenumberc-konggenumberb);} Tempchar = new Char[buffer.length ()];buffer.getchars (0, Buffer.length (), Tempchar, 0); String str = buffer.tostring (), if (Location > Str.length ()) {location = Str.length (),} else if (location < 0) {Locat ion = 0;} Etaccount.settext (str); Editable etable = Etaccount.gettext (); Selection.setselection (etable, location); ischanged = false;}}} Add this watcher to Edititex.
Android Bank card. Space input