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

编辑器加载中...本文实现的效果:文本框输入为空时显示输入的图标;不为空时显示清空的图标,此时点击清空图标能清空文本框内输入文字。
/**
* 动态搜索
*/
private TextWatcher tbxSearch_TextChanged = new TextWatcher() {

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

@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s)) {
if (!isnull) {
mSearchView.setCompoundDrawablesWithIntrinsicBounds(
null,
null, mIconSearchDefault, null);
isnull
= true;
}
}
else {
if (isnull) {
mSearchView.setCompoundDrawablesWithIntrinsicBounds(
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) {

}
};

具体内容请看安卓航班网 www.apkway.com

具体链接 http://www.apkway.com/forum.php?mod=viewthread&tid=1052&extra=page%3D2

posted on 2011-07-06 20:05  文艺小后生  阅读(245)  评论(0编辑  收藏  举报