Created
June 24, 2013 16:39
-
-
Save paddyzab/5851480 to your computer and use it in GitHub Desktop.
Formatting the Strings into blocks in EditTExt .
Usable for Credit Card Number :).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean splitFlag = true; | |
String splitBlock[] = copyTextField.getText().toString().split(" "); | |
for (int j = 0; j < splitBlock.length; j++) { | |
if (splitBlock[j].length() > 4) { | |
splitFlag = false; | |
} | |
} | |
if (splitFlag) { | |
copyTextField.setOnKeyListener(new View.OnKeyListener() { | |
@Override | |
public boolean onKey(View v, int keyCode, KeyEvent event) { | |
if (keyCode == KeyEvent.KEYCODE_DEL) { | |
keyDel = 1; | |
} | |
return false; | |
} | |
}); | |
if (keyDel == 0) { | |
if (((copyTextField.getText().length() + 1) % 5) == 0) { | |
if (copyTextField.getText().toString().split(" ").length <= 3) { | |
copyTextField.setText(copyTextField.getText() + " "); | |
copyTextField.setSelection(copyTextField.getText().length()); | |
} | |
} | |
a = copyTextField.getText().toString(); | |
} else { | |
a = copyTextField.getText().toString(); | |
keyDel = 0; | |
} | |
} else { | |
copyTextField.setText(a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment