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- ...
随机推荐
- ORACLE FORMS PL/SQL PACKAGE SHOW TIPS WINDOW
--在开发ORACLE FORM的程序中,要编写PL/SQL程序包产出异常情况时,直接在FORM弹出一个异常提示窗口 DECLARE BEGIN app_exception.raise_excepti ...
- python接口自动化10-token登录
前言 有些登录不是用cookie来验证的,是用token参数来判断是否登录. token传参有两种一种是放在请求头里,本质上是跟cookie是一样的,只是换个单词而已:另外一种是在url请求参数里,这 ...
- 使用openURL实现程序间带参数跳转详解
使用openURL实现程序间带参数跳转详解 实现的效果:有两款应用A与B,A打开B A --> B 1. 新建工程B,bundle ID为com.YouXianMing.B 建立一个URL 这么 ...
- 3D打印
R=2.5的内径圆,需要R=2.2的圆柱才能吻合,否则插不进去.
- [Gradle] Gradle 构建 android 应用常见问题解决指南
转载地址:http://www.cnblogs.com/youxilua/p/3348162.html 1: 使用最新的gradle android插件 以前我们写的时候会这么写 dependenci ...
- Python学习(五)函数 —— 内置函数 lambda filter map reduce
Python 内置函数 lambda.filter.map.reduce Python 内置了一些比较特殊且实用的函数,使用这些能使你的代码简洁而易读. 下面对 Python 的 lambda.fil ...
- 完整的ASP.NET存储过程分页,排序,鼠标移至变色
首先建立一个存储过程如下(MySQL数据库):CREATE DEFINER=`root`@`localhost` PROCEDURE `pagination`( in tbName var ...
- 值得阅读的C语言开源项目代码
本文地址:http://www.cnblogs.com/archimedes/p/c-opensource-project.html,转载请注明源地址. 本篇文章主要总结一些C开源项目,有些是很著名的 ...
- spring mvc--默认都使用了哪些bean
在MVC中默认使用的bean都定义在了 org.springframework.web.servlet下的DispatcherServlet.properties 下载源文件后可查看到默认bean定义 ...
- JQMobile引入外部CSS,JS文件
使用CDN <!DOCTYPE html> <html> <head> <title>html5</title> <meta name ...