TextWatcher
在Android里使用TextWatcher接口可以很方便的对EditText进行监听;TextWatcher中有3个函数需要重载:
public void beforeTextChanged(CharSequence s, int start,
int count, int after);
public void onTextChanged(CharSequence s, int start, int before, int count);
public void afterTextChanged(Editable s);
从函数名就可以知道其意思,每当敲击键盘编辑框的文字改变时,上面的三个函数都会执行,beforeTextChanged可以给出变化之前的内容,onTextChanged和afterTextChanged给出追加上新的字符之后的文本;
- classimplements * beginning at start are about to be replaced by new text with length after.
- * 在s中,从start处开始的count个字符将要被长度为after的文本替代
- * s 为变化前的内容;
- * start 为开始变化位置的索引,从0开始计数;
- * count 为将要发生变化的字符数
- * after 为用来替换旧文本的长度,比如s由1变为12,after为1,由12变为1,after为0;
- */
- publicvoidintint int
- , +s++start++count++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
- * 在s中,从start处开始的count个字符刚刚替换了原来长度为before的文本
- * s 为变化后的内容;
- * start 为开始变化位置的索引,从0开始计数;
- * before 为被取代的老文本的长度,比如s由1变为12,before为0,由12变为1,before为1;
- * count 为将要发生变化的字符数
- */
- publicvoidintint int
- , +s++start++before++count);
- * This method is called to notify you that, somewhere within s, the text has been changed.
- */
- publicvoid
- , +s);
- }
注册监听:
EditText mEditor = (EditText)findViewById(R.id.editor_input);
mEditor.addTextChangedListener(mTextWatcher);
TextWatcher的更多相关文章
- 使用EditText的addTextChangedListener(new TextWatcher())方法
(转:http://www.apkbus.com/android-5257-1-14.html) 在使用EditText的addTextChangedListener(new TextWatcher( ...
- TextWatcher 编辑框监听器
TextWatcher tw = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int sta ...
- Android TextWatcher监控EditText中的输入内容并限制其输入字符个数
布局中EditText在android布局中经常用到,对EditText中输入的内容也经常需要进行限制,我们可以通过TextWatcher去观察输入框中输入的内容,作个笔记. 主布局: <?xm ...
- 监听EditText变化---TextWatcher 类用法详解
http://www.cnblogs.com/yjing0508/p/5316985.html TextWatcher textWatcher = new TextWatcher() { @Overr ...
- 使用EditText+ListView并结合TextWatcher实现输入关键字筛选数据
想必大家应该遇到过这样的情况,当点击Spinner控件后弹出的列表内容超多,一个一个滑动着去寻找所要的项很麻烦,尤其是当自己知道想要选择的内容,这时候如果我们只需要输入某些关键字,就可以讲上百条数据筛 ...
- 使用TextWatcher监听EditText变化
public class MainActivity extends AppCompatActivity { private TextView mTextView; private EditText m ...
- AutoCompleteTextView与TextWatcher的结合
/******************************************************************************************** * au ...
- TextWatcher编辑框监听器
TextWatcher tw = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int sta ...
- AutoCompleteTextView 和 TextWatcher 详解
TextWatcher 监测Edittext内容的变化------------------------------------------------------------------------- ...
- android UI-EditText的长度监听慎用TextWatcher
在用户昵称的输入时,限定8个字符,本意是在输入超过8个时候,页面toast一个提示,就是下面的TextWatcher的监听,在afterTextChanged中处理. 原bug:huawei MT2- ...
随机推荐
- gitignore / Delphi.gitignore
https://github.com/github/gitignore/blob/master/Delphi.gitignore *.dcu *.~*~ *.local *.identcache __ ...
- [Win32]创建模态窗口
http://www.cnblogs.com/zplutor/archive/2011/02/20/1958973.html 在Win32编程中,如果要显示一个模态窗口,一般是先创建对话框模板,然后使 ...
- 按字母顺序排列的IDC函数列表
http://www.2cto.com/shouce/ida/162.htm 按字母顺序排列的IDC函数列表 下面是函数描述信息中的约定: 'ea' 线性地址 'success' 0表示函数失败:反之 ...
- 多线程间通信之AutoResetEvent和ManualResetEvent的原理分析和开发示例
AutoResetEvent 允许线程通过发信号互相通信. 通常,当线程需要独占访问资源时使用该类. 线程通过调用 AutoResetEvent 上的 WaitOne 来等待信号. 如果 AutoRe ...
- 简化delegate写法
标准的写法 空 简化后的宏 /**************************************************************/ // delegate 托付 /* #de ...
- 我的sourceinsight的配置
下面是我的sourceinsight的配置,点击下面的链接,下载*.em文件,将他们添加到Base工程,设置相应的快捷键即可,或者导入下载的配置文件. http://pan.baidu.com/s/1 ...
- mormot解析天气预报JSON数据
mormot解析天气预报JSON数据 uses SynCommons; constjson2 = '{' + #13#10 +'"error":0,' + #13#10 +'&qu ...
- React的第一个例子
准备: 官网:https://facebook.github.io/react/downloads.html Github地址:https://github.com/facebook/react 首先 ...
- 关于Go语言,自己定义结构体标签的一个妙用.
在Go中首字母大写和小写,决定着这此变量能否被外部调用, 比如:在使用标准库的json编码自定一的结构的时候: <pre style="margin-top: 0px; margin- ...
- pytest文档8-html报告报错截图+失败重跑
前言 做web自动化的小伙伴应该都希望在html报告中展示失败后的截图,提升报告的档次,pytest-html也可以生成带截图的报告. conftest.py 1.失败截图可以写到conftest.p ...