EditText의 문자수를 세고 싶어요.
조회수 5055회
제 프로젝트에서 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){}
});
댓글 입력