EditText TextWatch监听简单使用
2016-12-09 11:22
106 查看
TextWatch 接口方法如下:
方法执行顺序:beforeTextChanged() --> onTextChanged() --> afterTextChanged()
new TextWatcher() {
/**
* 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
*
* 在原来字符串 s 中,从 start 位置开始
* 正打算用 after 长度新字符串 替换 count 长度字符串
* @param s
* @param start
* @param count
* @param after
*/
@Override
public 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
* have just replaced old text that had length before.
* It is an error to attempt to make changes to s from this callback.
*
* 在改变后的字符串 s 中,从 start 位置开始
* 将 before 位的字符串 替换成为 count 位的字符串
*
* @param s 改变前的字符串
* @param start 开始发生替换初始index
* @param before 被替换掉字符串的大小
* @param count 替换字符串的大小
*/
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
/**
* 改变完后 对结果进一步的修改 注意不要发生迭代死循环
*/
@Override
public void afterTextChanged(Editable s) {
}也可以通过打印日志的方式进行验证。
通过对count、after、before等进行判定实现字符串自动补充,自动删除多个等操作,增强交互。
方法执行顺序:beforeTextChanged() --> onTextChanged() --> afterTextChanged()
new TextWatcher() {
/**
* 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
*
* 在原来字符串 s 中,从 start 位置开始
* 正打算用 after 长度新字符串 替换 count 长度字符串
* @param s
* @param start
* @param count
* @param after
*/
@Override
public 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
* have just replaced old text that had length before.
* It is an error to attempt to make changes to s from this callback.
*
* 在改变后的字符串 s 中,从 start 位置开始
* 将 before 位的字符串 替换成为 count 位的字符串
*
* @param s 改变前的字符串
* @param start 开始发生替换初始index
* @param before 被替换掉字符串的大小
* @param count 替换字符串的大小
*/
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
/**
* 改变完后 对结果进一步的修改 注意不要发生迭代死循环
*/
@Override
public void afterTextChanged(Editable s) {
}也可以通过打印日志的方式进行验证。
通过对count、after、before等进行判定实现字符串自动补充,自动删除多个等操作,增强交互。
相关文章推荐
- TextWatcher接口的使用:监听EditText文字变动事件
- 简单使用技巧 隐藏键盘, 判断软键盘是否打开. edittext解决第二次点击获取焦点
- 安卓onTextChanged参数解释及实现EditText字数监听 Editable使用
- 安卓onTextChanged参数解释及实现EditText字数监听 Editable使用
- Android 超简单音乐播放器(三)根据歌曲名或者歌手搜索本地音乐(EditText监听)
- 每周一篇之EditText的简单使用
- EditText 的简单使用
- Android学习笔记 EditText的简单使用
- [置顶] 安卓onTextChanged参数解释及实现EditText字数监听 Editable使用
- 使用TextWatcher监听EditText变化
- Fragment的一个简单实现+EditText的监听事件
- 如何安装和使用+Http+Watch+服务器+监听工具+【上】
- Android 各控件的使用 - 可编辑文本框(EditText)
- Android的TextView/EditText使用CharacterStyle&SpannableString来处理图片显示、字体样式、超链接等
- TextView的简单使用
- EditText输入事件截获与监听
- Android EditText聚焦时hint消失的简单代码
- Android系列教程之七:EditText使用详解-包含很多教程上看不到的功能演示
- 【问题】在TabHost以外的EditText不能使用硬件盘输入数字
- android EditText使用指南