I readed a lot of similar questions, but no one answers mine or can solve my problem. I have a EditText like this in the layout:
<EditText
android:id="@+id/editText2"
android:layout_width="248dp"
android:layout_height="59dp"
android:layout_marginStart="21dp"
android:layout_marginTop="36dp"
android:width="360dp"
android:ems="5"
android:hint="@string/ultimos4Dig"
android:inputType="number"
android:maxLength="10"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I need that when the user are writing the numers of the month and year, a slash appear or disappearwhen he is writing. If he writes 2 numbers then a slash needs to appear. If he erases and its only one number, then the slash needs to disappear.
I need that in the editText appears the date as: 14/06
Here is my code but its not working.
protected void onCreate(Bundle savedInstanceState) {
EditText editText2 = (EditText) findViewById(R.id.editText2);
editText2.addTextChangedListener(new TextWatcher() {
@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 text) {
if (text.length() == 2) {
text.append('/');
}
}
});
FYI i made a class for a solution of this, thanks