Android Bank card. Space input

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.