The issues and string manipulation needed with text based date entry just doesn't seem worth it here. What happens if a user goes back to the beginning of the string and starts typing? What happens if a user starts entering the wrong format? You have to account for a ton of cases without having a very good way of controlling what the user can input. In these instances, I'd just use a DatePicker like the one in this solution.
You can keep the EditText if you have your heart set on it, and just set the onClickListener to bring up the DatePicker when selected. I recommend setting these two fields on it though:
android:cursorVisible="false"
android:focusable="false"
This way the EditText won't look like it can be typed in. My only suggestion or addition to the other answer would be a "Clear" button so the EditText value can be wiped if needed. To do so, just add it via the neutral button like so:
builder.setView(dialog)
// Add action buttons
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
listener.onDateSet(null, yearPicker.getValue(), monthPicker.getValue(), 0);
}
})
.setNeutralButton(R.string.clear, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//check for a month value of -1 in onDateSet to clear current field
listener.onDateSet(null, -1, -1, 0);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MonthYearPickerFragment.this.getDialog().cancel();
}
});
Then to check and see if the field should be cleared, just do something like this:
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
if (i > -1){
et.setText(i1 + "/" + i);
} else {
et.setText("");
}
}