Android: On EditText Changed Listener
来源:互联网 发布:中标麒麟怎么卸载软件 编辑:程序博客网 时间:2024/05/02 01:13
Android: On EditText Changed Listener
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){} });
TextWatcher
implements NoCopySpanClass Overview
When an object of a type is attached to an Editable, its methods will be called when the text is changed.
Summary
s
, the text has been changed.s
, the count
characters beginning at start
are about to be replaced by new text with length after
.s
, the count
characters beginning at start
have just replaced old text that had length before
.Public Methods
public abstract void afterTextChanged (Editable s)
This method is called to notify you that, somewhere within s
, the text has been changed. It is legitimate to make further changes to s
from this callback, but be careful not to get yourself into an infinite loop, because any changes you make will cause this method to be called again recursively. (You are not told where the change took place because other afterTextChanged() methods may already have made other changes and invalidated the offsets. But if you need to know here, you can use setSpan(Object, int, int, int)
in onTextChanged(CharSequence, int, int, int)
to mark your place and then look up from here where the span ended up.
public abstract void beforeTextChanged (CharSequence s, int start, int count, int after)
This method is called to notify you that, within s
, the count
characters beginning at start
are about to be replaced by new text with length after
. It is an error to attempt to make changes to s
from this callback.
public abstract void onTextChanged (CharSequence s, int start, int before, int count)
This method is called to notify you that, within s
, the count
characters beginning at start
have just replaced old text that had length before
. It is an error to attempt to make changes to s
from this callback.
- Android: On EditText Changed Listener
- android-edittext
- android edittext
- android edittext
- Android:EditText
- android-----EditText
- android Edittext
- Android EditText
- android edittext
- android Edittext
- android EditText
- android editText
- Android EditText
- Edittext ---Android
- Android EditText
- Belgium: British Consumers May be 'Short Changed' on Winter Clothing
- Beware EditText on API 21
- Android View添加 Listener
- 主线程自动退出问题
- plsql乱码如何解决
- Android APK反编译详解(附图)
- Tcl 快速入门
- linux 文件属性
- Android: On EditText Changed Listener
- 浅谈在线考试系统的监考设计问题
- excel导入csv格式 身份证号就变成科学计数法了
- Eclipse Plugin 开发 备忘贴 (Contribution to Eclipse)
- 说说产品经理的“需求真相”
- Android 4.2 Wifi Display 之 Settings 源码分析(二)
- Spring框架
- JQuery 权限选择(可以排序)
- 使用xml 控制imageview的缩放