Created
April 13, 2018 11:45
-
-
Save hasankucuk/4afc0a6abb8bcd53af1ea56c80d24973 to your computer and use it in GitHub Desktop.
To make / between expiration month and year
This file contains hidden or 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
mEdtPaymentAuthorCreditExpirationDate.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |
mLength = mEdtPaymentAuthorCreditExpirationDate.getText().length(); | |
} | |
@Override | |
public void onTextChanged(CharSequence charSequence, int start, int before, int count) { | |
int currentLength = mEdtPaymentAuthorCreditExpirationDate.getText().length(); | |
boolean ignoreBecauseIsDeleting = false; | |
if (mLength > currentLength) { | |
ignoreBecauseIsDeleting = true; | |
} | |
if (ignoreBecauseIsDeleting) { | |
return; | |
} | |
if (charSequence.length() == 2 && !charSequence.toString().contains("/")) { | |
String cleanString = charSequence.toString().replaceAll("[/,.]", ""); | |
mEdtPaymentAuthorCreditExpirationDate.setText(cleanString + " / "); | |
mEdtPaymentAuthorCreditExpirationDate.setSelection(charSequence.length() + 3); | |
mEdtPaymentAuthorCreditExpirationDate.addTextChangedListener(this); | |
} | |
} | |
@Override | |
public void afterTextChanged(Editable editable) { | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment