EditText에 TextWatcher를 달아서 이벤트를 처리하는 구문을 짜고있습니다.
매 입력마다 입력받은 마지막 문자를 onTextChanged에서 s.charAt(before)로 받으려는데
스페이스와 백스페이스, 엔터는 입력이 잘 안됩니다. (count가 증가하지 않는 것 같습니다)
public void onTextChanged(CharSequence s, int start, int before, int count) {
char c;
c = s.charAt(before);
checkRight(c);
if (c == '\b '){ // should be changed later
//...
}
else if (c == '\n') {
//...
}
else {
//...
}
}
이런 식으로 사용하고 싶은데 스페이스나 백스페이스, 엔터를 입력할 때마다
06-25 21:24:51.078: E/AndroidRuntime(7068): java.lang.IndexOutOfBoundsException: charAt: 3 >= length 2
06-25 21:24:51.078: E/AndroidRuntime(7068): at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:114)
06-25 21:24:51.078: E/AndroidRuntime(7068): at edu.esrc.QwertyTest.AnEventMove$1.onTextChanged(AnEventMove.java:76)
이런 인덱스 아웃 바운더리 예외가 발생합니다ㅜㅜ
keycode를 받아서 따로 처리해야 할까요?
(dispatchKeyEvent 함수를 사용하려 해봤으나 이벤트가 안 잡히더라구요 제가 쓸 줄을 모르는건지ㅜ)