您的位置:首页 > 移动开发 > Android开发

监听多个EditText,满足条件后Button才可以点击

2016-03-12 20:04 501 查看

先翻译下Google文档对TextWatcher的介绍

MethodDescription
abstract void afterTextChanged(Editable s)This method is called to notify you that, somewhere within s, the text has been changed.
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.
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.
方法描述
abstract void afterTextChanged(Editable s)调用此方法会通知你text文本已经变化了, text文本变为s(即变化后最终的text),如果你需要知道Text的那个地方变化了,可以在onTextChanged()中调用setSpan(object,int,int,int)来标记哪个地方变化了
abstract void beforeTextChanged(CharSequence s, int start, int count, int after)调用此方法主要是通知你,文本s将要发生改变,改变前文本的长度为start,变化后,文本长度增加count,新的文本长度为after
abstract void onTextChanged(CharSequence s, int start, int before, int count)调用此方法会通知你,文本变为s,旧文本长度为before,旧文本的长度为start,新文本长度增加了count(一般使用start+count来从s中读取新增文本)
想要进一步对新文本进行变化, 不要在onTextChanged()中, 而要选择在afterTextChanged(),但是不要让自己陷入循环中,因为任何一次文本的变化都会调用afterTextChange()方法而重置变化起始点,想要知道文本哪儿变化了可以考虑在onTextChange()中调用setSpan()给新增文本做标记.

实现多EditText监听: TODO:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  文档 android