In my project I have a EditText
. I want to show how many characters are there in the EditText
and show it in the TextView
. I have written following code and it works fine. However, my problem is when I click Backspace it counts up. I need to decrement the number. What should I do? How can I take Backspace Key?
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){}
});