OnFocusChangeListener 가 제대로 작동을 안합니다.
조회수 5022회
EditText의 포커스가 풀릴 때 이메일 체크를 하려고 하는데요.
이메일을 입력하고 다른 EditText로 옮겨가면 한번은 정상적(정상이든 오류메세지를 보여주던)으로 작동을 합니다.
근데 이메일을 입력하는 EditText로 다시 돌아와서, 이메일 형식과 맞지 않게 수정을 하고 다른 EditText로 옮겨가면 에러 메세지를 보여주지 않습니다.
signup_email.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
String mailFormat = "^[_a-zA-Z0-9-\\.]+@[\\.a-zA-Z0-9-]+\\.[a-zA-Z]+$";
if (hasFocus == false) {
String inputText = signup_email.getText().toString();
Pattern pattern = Pattern.compile(mailFormat);
Matcher matcher = pattern.matcher(inputText);
signup_email_layout.setErrorEnabled(false);
if (!matcher.matches())
signup_email_layout.setError("이메일 입력이 잘못되었습니다");
}
}
});
1 답변
-
위의 코드로 저도 테스트를 해봤는데요 포커스 바뀔때마다
setOnFocusChangeListener
가 잘 호출되고 있습니다.setErrorEnabled(false);
함수에서는 뭘 수행하고 있나요? true로는 언제 설정해주나요? 플래그 셋팅이 잘못된것 같아요 :)signup_email.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { String mailFormat = "^[_a-zA-Z0-9-\\.]+@[\\.a-zA-Z0-9-]+\\.[a-zA-Z]+$"; if (hasFocus == false) { String inputText = signup_email.getText().toString(); Pattern pattern = Pattern.compile(mailFormat); Matcher matcher = pattern.matcher(inputText); if (!matcher.matches()) { Log.d("TEST", "이메일이 맞지 않습니다."); // 저는 로그를 찍어봤는데요. 포커스 이동될때마다 로그가 잘 찍히고 있습니다. } } } });
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력