1 / 4
文档名称:

[Android]文本框实现搜索和清空效果.pdf

格式:pdf   页数:4
下载后只包含 1 个 PDF 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

[Android]文本框实现搜索和清空效果.pdf

上传人:翩仙妙玉 2012/7/14 文件大小:0 KB

下载得到文件列表

[Android]文本框实现搜索和清空效果.pdf

文档介绍

文档介绍:[Android]文本框实现搜索和清空效果
前言
本文实现的效果:文本框输入为空时显示输入的图标;不为空时显示清空的图标,此时点击
清空图标能清空文本框内输入文字。
声明
欢迎转载,但请保留文章原始出处:)
博客园:
农民伯伯:
正文
一、实现效果


二、实现代码
监听输入
/**
* 动态搜索
*/
private TextWatcher tbxSearch_TextChanged = new TextWatcher() {

//缓存上一次文本框内是否为空
private boolean isnull = true;

***@Override
public void afterTextChanged(Editable s) {
if ((s)) {
if (!isnull) {
(null,
null, mIconSearchDefault, null);
isnull = true;
}
} else {
if (isnull) {
(null,
null, mIconSearchClear, null);
isnull = false;
}
}
}

***@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}

/**
* 随着文本框内容改变动态改变列表内容
*/
***@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {

}
};
触摸事件
private OnTouchListener txtSearch_OnTouch = new OnTouchListener() {
***@Override
public boolean onTouch(View v, MotionEvent event) {
switch (()) {
case :
int curX = (int) ();
if (curX > () - 38
&& !(())) {
("");
int cacheInputType = ();// backup the input ty
pe
();// disable soft input