TextWatcher接口中方法参数说明
2015-08-13 12:55
375 查看
简述:Android中EditText等控件监听文本内容的更改使用的是TextWatcher接口,但是官方文档对该接口中方法的参数说明很模糊,在此记录下对方法参数的认识(随认识的增加逐步完善)
public interface TextWatcher extends NoCopySpan { /** * This method is called to notify you that, within <code>s</code>, * the <code>count</code> characters beginning at <code>start</code> * are about to be replaced by new text with length <code>after</code>. * It is an error to attempt to make changes to <code>s</code> from * this callback. */ public void beforeTextChanged(CharSequence s, int start, int count, int after); /** * 文本更改后的回调(使用时发现,小米手机,粘贴时前后都会默认加一个空格, * 造成参数的数字不准确,不知其他手机有无此情况,此处以键盘输入或删除为 * 准。) * @param s * 更改以后现存的字符串 * @param start * 新增字符:该值为新增字符所在的下标 * 删除字符:该值为删掉字符所在的先 * @param before * 新增字符:该值为0 * 删除字符:该值为删掉的字符数 * @param count * 新增字符:值为新增字符数 * 删除字符:值为0 */ public void onTextChanged(CharSequence s, int start, int before, int count); /** * This method is called to notify you that, somewhere within * <code>s</code>, the text has been changed. * It is legitimate to make further changes to <code>s</code> 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 {@link Spannable#setSpan} in {@link #onTextChanged} * to mark your place and then look up from here where the span * ended up. */ public void afterTextChanged(Editable s);
相关文章推荐
- 最强理解:Android对EditText输入时设置监听即TextWatcher的用法
- TextWacher 监听EditText中的文本变化
- Android:EditText动态输入监听TextWatcher
- 监听EditText文字变化,TextWatcher详解
- Android TextWatcher使用详解
- jedis连接池详解(Redis)
- 简单的比较两数大小
- 算法思想篇(4)————分治算法
- HashMap和HashSet的区别
- 机房收费系统个人重构版:透过文档谈文档驱动开发
- STL源码剖析——空间的配置与释放
- 程序员30后发展
- 随机取中文名字,百家姓,2500个常见字,支持复姓
- Xcode 修改工程名称
- Xamarin for VS 3.11.1594 Stable版免费完整破解补丁
- 逃离迷宫
- 在 Eclipse 中打开本地文件浏览器的方法
- 讲故事的人写的谈判手册——Leo锦书64
- Swing文档大全 - Swing中树(Tree)的使用与介绍
- Java代码优化策略