Last active
May 8, 2018 08:41
-
-
Save hasankucuk/ed90351efbc0818e11c75d0a3a1205db 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 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