Android: On EditText Changed Listener

来源:互联网 发布:中标麒麟怎么卸载软件 编辑:程序博客网 时间:2024/05/02 01:13

Android: On EditText Changed Listener

up vote68down votefavorite
14

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){}    }); 
原创粉丝点击