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