I’ve got some straightforward regex validation on an editText element. The problem I have is that the error shows immediately if it fails the validation (even if the user is still typing), which isn’t nice UX. Here’s the code currently.
TextWatcher tw = new TextWatcher() {
public void afterTextChanged(Editable s) {
String currentTime = t_timeEditText.getText().toString();
if (!validTimepattern.matcher(currentTime).matches()){
timeEditText.setError("Not a valid time");
}
}
}
I think the best solution would be to wait until the focus moves off the editText element before running the above validation. Alternatively, we could wait for X milliseconds since the last input before running the validation, or just add some nasty hardcoded delay in there.
Any suggestions?