Bank card Input Effect 4 plus a space

Source: Internet
Author: User

private static Final charKongge="';
PrivateTextwatcherTextwatcher=NewTextwatcher () {

//before the changetextlength
intBeforetextlength=0;
//Change the text before
PrivateCharsequenceBeforechar;
//after the changetextlength
intOntextlength=0;
//Whether to change the space or cursor
Booleanischanged=false;
// record the position of the cursor
int Location=0;
Private Char[]Tempchar;
PrivateStringBufferBuffer=NewStringBuffer ();
//number of spaces already available
intKonggenumberb=0;

@Override
Public voidbeforetextchanged(Charsequence s, intStart, intCount, intAfter) {
Beforetextlength= S.length ();
if(Buffer. Length () >0) {
Buffer. Delete (0, Buffer. Length ());
}
Konggenumberb=0;
for(inti =0; I < S.length (); i++) {
if(S.charat (i) = ="') {
Konggenumberb++;
}
}
}

@Override
Public voidontextchanged(Charsequence s, intStart, intBefore, intCount) {

Ontextlength= S.length ();
Buffer. Append (S.tostring ());
if(Ontextlength==Beforetextlength||Ontextlength<=3
||ischanged) {
ischanged=false;
return;
}
ischanged=true;

}

@Override
Public voidaftertextchanged(Editable s) {
off(ischanged) {
Location=yourcardnumed. Getselectionend ();
intindex =0;
while(Index <Buffer. Length ()) {
if(Buffer. charAt (Index) = =Kongge) {
Buffer. Deletecharat (Index);
}Else{
index++;
}
}
index =0;
intKONGGENUMBERC =0;
while(Index <Buffer. Length ()) {
off(Index = =4|| index = =9|| index = = -|| index = = +)) {
Buffer. Insert (Index, Kongge);
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) {
Location=0;
}

yourcardnumed. SetText (str);
Editable etable =yourcardnumed. GetText ();
if( Location> -){
Toastutil.Toastshow("to enter at most -bit");
return;
}

Selection.setselection(etable, Location);

ischanged=false;
}
}

};

Bank card Input Effect 4 plus a space

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.