Skip to content

Instantly share code, notes, and snippets.

@hasankucuk
Last active May 8, 2018 08:41
Show Gist options
  • Save hasankucuk/ed90351efbc0818e11c75d0a3a1205db to your computer and use it in GitHub Desktop.
Save hasankucuk/ed90351efbc0818e11c75d0a3a1205db to your computer and use it in GitHub Desktop.
To make / between expiration month and year
mEdtPaymentAuthorCreditExpirationDate.addTextChangedListener(new ExpirationDateFormatWatcher());
import android.text.Editable;
import android.text.TextWatcher;
public class ExpirationDateFormatWatcher implements TextWatcher {
private int mLength;
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
mLength = charSequence.length();
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
int currentLength = editable.length();
boolean ignoreBecauseIsDeleting = false;
if (mLength > currentLength) {
ignoreBecauseIsDeleting = true;
}
if (ignoreBecauseIsDeleting) {
return;
}
if (editable.length() == 2 && !editable.toString().contains("/")) {
editable.insert(editable.length(), " / ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment