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- ...
随机推荐
- X86调用约定 calling convention
http://zh.wikipedia.org/wiki/X86%E8%B0%83%E7%94%A8%E7%BA%A6%E5%AE%9A 这里描述了在x86芯片架构上的调用约定(calling con ...
- linkhashmap实现原理
HashMap和双向链表合二为一即是LinkedHashMap.所谓LinkedHashMap,其落脚点在HashMap,因此更准确地说,它是一个将所有Entry节点链入一个双向链表的HashMap. ...
- CentOS6.5使用yum命令方便快捷安装Nginx与卸载
原文:https://my.oschina.net/ramboo/blog/223408 当然,首先要求是可以联网的CentOS系统,因为yum安装需要互联网连接. 卸载命令:yum remove n ...
- 【redis】spring boot中 使用redis hash 操作 --- 之 使用redis实现库存的并发有序操作
示例: @Autowired StringRedisTemplate redisTemplate; @Override public void dealRedis(Dealer dealer) { d ...
- cocos2d-x 环境搭建
刚搬到博客园,第一次在这写博.有点小激动啊~~ 闲话不多说,这次想做一个专题,针对最近比较流行的手游开发引擎cocos2d-x,希望大家不吝赐教~ 本节主要针对环境搭建方面进行 ...
- Linuxg挂载
在linux操作系统中, 挂载是指将一个设备(通常是存储设备)挂接到一个已存在的目录上. 我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的目录上, 然后通过访问这个目录来访问存储设备 ...
- 在上已个Java Spring MVC项目基础上加MyBatis
代码目录: /Users/baidu/Documents/Data/Work/Code/Self/HelloSpringMVC 1. 首先在resource目录加上jdbc.properties: d ...
- DICOMDIR结构
DICOMDIR文件结构: 格式: DICOMDIR文件遵照DICOM文件的存储格式,需要有128个无意义字节的前言(假如没有特殊要求,这些字节都为00H),紧接着是DICOM前缀(长度为4字节的“D ...
- go语言基础之递归实现数字累加
1.实现1+100 = 5050 示例: package main import "fmt" //实现1+2+3+……100 func test01() (sum int) { f ...
- 利用FPGA实现PCI总线接口及Windows驱动实现
利用FPGA实现PCI总线接口及Windows驱动实现 关于PCI总线协议,资料网上.书本都是.这里我们仅仅对重点对利用FPGA实现PCI总线接口问题进行简单分析.下图是PCI总线接口信号: 配置空间 ...