<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="Android开发中文本框中搜索和清空效果实现" id="card1">
<p> 游客</p><p>
标题:Android开发中文本框中搜索和清空效果实现<br/>
正文:<br/>
 　　正文 　　一、实现效果　　二、实现代码　　监听输入　　/**　　* 动态搜索　　*/　　private TextWatcher tbxSearch_TextChanged = new TextWatcher() {　　//缓存上一次文本框内是否为空 @camnpr　　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) {　　}　　};　　触摸事件　　private OnTouchListener txtSearch_OnTouch = new OnTouchListener() {　　@Override　　public boolean onTouch(View v, MotionEvent event) {　　switch (event.getAction()) {　　case MotionEvent.ACTION_UP:　　int curX = (int) event.getX();　　if (curX &amp;gt; v.g<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1756&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1756&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1756&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1756&amp;Page=3">[3]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1756&amp;Page=3">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1756">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1756">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>