EditText의 문자수를 세고 싶어요.

조회수 5126회

제 프로젝트에서 EditText가 있는데 여기서 EditText의 문자수를 세고싶어요. 그리고 그 숫자를 TextView에 출력하려고 밑의 코드를 짰는데요. 잘되는데 제가 백스페이스를 입력하면 문자수가 줄어야되는데 백스페이스도 문자로 인식해서 오히려 문자수가 증가해요. 어떻게하면 좋을까요?

소스코드

tv = (TextView)findViewById(R.id.charCounts);
textMessage = (EditText)findViewById(R.id.textMessage);
textMessage.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s) {
        i++;
        tv.setText(String.valueOf(i) + " / " + String.valueOf(charCounts));
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count){}
}); 

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)