I have a problem, I need a editText with validation and a effect hide numbers the credit card except the last 3 numbers..
I have the mask and work fine, but I need show the last 3 numbers.
How can I create this effect?
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/creditCard"
android:layout_below="@+id/CVV"
android:inputType="number"
android:digits=" 1234567890"
android:maxLength="16"
android:layout_alignParentStart="true" />
class TarjetasBancarias
public class TarjetasBancarias extends AppCompatActivity {
String a;
int keyDel;
private EditText creditCard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tarjetas_bancarias);
creditCard = (EditText)findViewById(R.id.creditCard);
creditCard.addTextChangedListener(new CreditCardNumberFormattingTextWatcher());
}
class CreditCardNumberFormattingTextWatcher
public static class CreditCardNumberFormattingTextWatcher implements TextWatcher {
private boolean lock;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (lock || s.length() > 16) {
return;
}
lock = true;
for (int i = 4; i < s.length(); i += 5) {
s.insert(i, "*");
if (s.toString().charAt(i) != ' ') {
s.insert(i, " ");
}
}
lock = false;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…