Escribir en un EditText tipo tarjeta de crédito
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //s.charAt(0) == '-' && s.length() == 1 if (s.toString().length() != 0) { if (s.toString().charAt(0) == '-') { if (s.length() != 1) { String aux = s.toString().substring(1); if (aux.length() <= 16) { int aux2 = aux.length(); aux2 = aux2 - aux2 % 4; StringBuilder sb = new StringBuilder(); for (int i = 0; i < aux.length(); i++) { if (i % 4 == 0 && i != 0) { sb.append("-"); } sb.append(aux.charAt(i)); }