TextWatcher() 的用法

实例一:

phone_view.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before, int count) {

Log.i(TAG, "onTextChanged =" + s + " start:" + start + " before:" + before + " count " + count);

if(application.contactPersionList ==null || application.contactPersionList.size()==0 || "".equals(s.toString())){

listView.setVisibility(View.INVISIBLE);

callLogList.setVisibility(View.VISIBLE);

}else{

if(null == t9Adapter){

t9Adapter = new T9Adapter(HomeDialActivity.this);

contactList.addAll(application.contactPersionList);

t9Adapter.assignment(contactList);

listView.setAdapter(t9Adapter);

listView.setTextFilterEnabled(true);

listView.setOnScrollListener(new OnScrollListener() {

public void onScrollStateChanged(AbsListView view, int scrollState) {

if(scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){

if(bohaopan.getVisibility() == View.VISIBLE){

bohaopan.setVisibility(View.GONE);

}

}

}

public void onScroll(AbsListView view, int firstVisibleItem,

int visibleItemCount, int totalItemCount) {

}

});

}

t9Adapter.getFilter().filter(s);

}

}

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

Log.i(TAG, "beforeTextChanged =" + s + " start:" + start + " after:" + after + " count " + count);

}

public void afterTextChanged(Editable s) {

Log.i(TAG, "afterTextChanged = " + s.toString());

String phone = s.toString();

//对长度进行判断;

if(!TextUtils.isEmpty(phone) && phone.length() >= 10 && phone.length() <= 15){

if(!Utils.isMcwillNumber(phone) && AppUtils.isSipConnected(HomeDialActivity.this)){//非M网,则进行远端查询

new AsySearchOnLineTask(phone).execute();

}

}

}

});

实例二:

etSearch = (EditText)findViewById(R.id.etSearch);

etSearch.addTextChangedListener(searchWatcher);

TextWatcher searchWatcher = new TextWatcher() {

@Override

public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

if(chatHistoryAdapter != null){

chatHistoryAdapter.getFilter().filter(arg0);

}

}

@Override

public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,

int arg3) {

}

@Override

public void afterTextChanged(Editable arg0) {

}

};

实例三:

editText1 = (EditText) findViewById(R.id.lin_search_edit);

editText1.addTextChangedListener(new TextWatcher() {

@Override

public void afterTextChanged(Editable edit) {

if (adapter != null) {

adapter.getFilter().filter(edit);

}

}

@Override

public void beforeTextChanged(CharSequence charsequence, int i,int j, int k) {

}

@Override

public void onTextChanged(CharSequence charsequence, int i, int j,int k) {

}

});

实例四:

// 搜索的监听

edit_input.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override

public void afterTextChanged(Editable s) {

if(adapter!=null)

{

adapter.getFilter().filter(s);

}

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

};

});

实例五:

editText1.addTextChangedListener(new TextWatcher() {

@Override

public void afterTextChanged(Editable edit) {

if (adapter != null && isNeedFilter) {

adapter.getFilter().filter(edit);// Adapter类中实现Filterable方法,并且重写getFilter()

}

}

@Override

public void beforeTextChanged(CharSequence charsequence, int i,

int j, int k) {

}

@Override

public void onTextChanged(CharSequence charsequence, int i, int j,

int k) {

}

});

实例六:

meetingReplyMsg.addTextChangedListener(textWatcher);

/**

* TextWatcher

*/

TextWatcher textWatcher = new TextWatcher() {

@Override

public void afterTextChanged(Editable s) {

System.out.println("---s.toString()---:" + s.toString());

if (!Utils.isStrEmpty(s.toString())) {

Config._reply_msg.set(s.toString().trim());

}

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

}

@Override

public void onTextChanged(CharSequence s, int start, int before,

int count) {

}

};

实例七:

mEdPhone.addTextChangedListener(new TextWatcher() {

@Override

public void onTextChanged(CharSequence s, int start, int before,

int count) {

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

}

@Override

public void afterTextChanged(Editable s) {

if (s.toString().length() > 0) {

mBtnRegister.setClickable(true);

mBtnRegister.setBackgroundResource(R.drawable.loginbtn);

} else if (s.toString().length() == 0) {

mBtnRegister.setClickable(false);

mBtnRegister

.setBackgroundResource(R.drawable.button_no_cliable);

}

mPhoneNumber = mEdPhone.getText().toString().trim();

}

});

实例八:

editText1.addTextChangedListener(new TextWatcher() {

@Override

public void afterTextChanged(Editable edit) {

if (adapter != null) {

adapter.getFilter().filter(edit);

}

}

@Override

public void beforeTextChanged(CharSequence charsequence, int i,

int j, int k) {

}

@Override

public void onTextChanged(CharSequence charsequence, int i, int j,

int k) {

}

});

实例九:

// 获取编辑框焦点

editText.setFocusable(true);

editText.addTextChangedListener(new TextWatcher() {

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

// TODO Auto-generated method stub

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

// TODO Auto-generated method stub

}

@Override

public void afterTextChanged(Editable s) {

// TODO Auto-generated method stub

editText.setSelection(s.length());

Log.v("CustomDialog", "666666"+s.length());

}

});

实例十:

searchBox = (EditText) view.findViewById(R.id.com_facebook_picker_search_text);

searchBox.addTextChangedListener(new SearchTextWatcher());

if (!TextUtils.isEmpty(searchText)) {

searchBox.setText(searchText);

}

private class SearchTextWatcher implements TextWatcher {

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

onSearchBoxTextChanged(s.toString(), false);

}

@Override

public void afterTextChanged(Editable s) {

}

}

时间: 2024-10-02 09:53:15

TextWatcher() 的用法的相关文章

监听EditText变化---TextWatcher 类用法详解

http://www.cnblogs.com/yjing0508/p/5316985.html TextWatcher textWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { //s--未改变之前的内容 //start--内容被改变的开始位置 //count--原始文字被删除的个数 //after--新添

android中RadioGroup、RadioButton、Spinner、EditText用法详解(含示例截图和源代码)

为了保护版权.尊重原创,转载请注明出处:http://blog.csdn.net/u013149325/article/details/43237757,谢谢! 今天在项目中用到了android中常用的RadioGroup.RadioButton.Spinner.EditText等控件,在此介绍一下它们的用法,希望对需要的朋友有帮助. 一.RadioGroup和RadioButton的使用 RadioButton就是我们常见的单选按钮,一个RadioGroup可以包含多个单选按钮,但是每次只能选

使用EditText+ListView并结合TextWatcher实现输入关键字筛选数据

想必大家应该遇到过这样的情况,当点击Spinner控件后弹出的列表内容超多,一个一个滑动着去寻找所要的项很麻烦,尤其是当自己知道想要选择的内容,这时候如果我们只需要输入某些关键字,就可以讲上百条数据筛选出几十条甚至更少,岂不是会方便很多. 其实这是项目中的一个需求,由于目前公司接触的多数和数据采集相关的PDA项目,有很多填写项一个spinner已经不方便满足需求,虽然客户还没有提 出,但提前做好优化总是没有错的,所以项目组的同事提出这个需求并让我尝试着去做出来,当中给了我不少帮助和意见. 闲言少

RxAndroid 常见用法

RxAndroid 常见用法 在项目里面添加 compile 'io.reactivex:rxandroid:1.1.0' // Because RxAndroid releases are few and far between, it is recommended you also // explicitly depend on RxJava's latest version for bug fixes and new features. compile 'io.reactivex:rxja

我的Android进阶之旅------&gt;Android关于TextWatcher的初步了解

首先来看一下TextWatcher的源代码 package android.text; /** * When an object of a type is attached to an Editable, its methods will * be called when the text is changed. */ public interface TextWatcher extends NoCopySpan { /** * This method is called to notify y

js中获取时间new date()的用法

js中获取时间new date()的用法 获取时间:   var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份(4位,1970-????) 3 myDate.getMonth(); //获取当前月份(0-11,0代表1月) 4 myDate.getDate(); //获取当前日(1-31) 5 myDate.getDay();

20.5 Shell脚本中的逻辑判断;20.6 文件目录属性判断;20.7 if特殊用法;20.8 20.9 cace判断(上下)

扩展: select用法 http://www.apelearn.com/bbs/thread-7950-1-1.html 20.5 Shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi 1. 创建if1.sh测试脚本: [[email protected] ~]# vi if1.sh a=5,如果a大于3,满足这个条件,显示ok 添加内容: #!/bin/bash a=5 if [ $a -gt 3 ] then echo ok fi 2. 执行if1.sh脚本: [[e

20.1 Shell脚本介绍;20.2 Shell脚本结构和执行;20.3 date命令用法;20.4 Shell脚本中的变量

20.1 Shell脚本介绍 1. shell是一种脚本语言 aming_linux blog.lishiming.net 2. 可以使用逻辑判断.循环等语法 3. 可以自定义函数 4. shell是系统命令的集合 5. shell脚本可以实现自动化运维,能大大增加我们的运维效率 20.2 Shell脚本结构和执行 1. 开头(首行)需要加: #!/bin/bash 2. 以#开头的行作为解释说明: 3. 脚本的名字以.sh结尾,用于区分这是一个shell脚本 4. 执行.sh脚本方法有两种:

shell 中seq的用法 echo -n用法

用法:seq [选项]... 尾数 或:seq [选项]... 首数 尾数 或:seq [选项]... 首数 增量 尾数 从1循环到100的两种方法(bash 其它的shell没试过)for x in `seq 1 100`;do echo $x;donefor x in {1..100};do echo $x;done echo -n 不换行输出 $echo -n "123" $echo "456" 最终输出 123456 echo -e 处理特殊字符 若字符串中