Skip to content

Instantly share code, notes, and snippets.

@paddyzab
Created June 24, 2013 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paddyzab/5851480 to your computer and use it in GitHub Desktop.
Save paddyzab/5851480 to your computer and use it in GitHub Desktop.
Formatting the Strings into blocks in EditTExt . Usable for Credit Card Number :).
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