我想搜索listView中有4列的特定列。 也许我只是想搜索"单词"列。
不知何故,textwatcher还会过滤所有列
这是我的textWatcher代码
etsearch.addTextChangedListener(new 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) {
simpleAdapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
这里是行xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtid"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="TextView"
android:gravity="center"
/>
<TextView
android:id="@+id/txtwords"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="TextView"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:id="@+id/txtvideofilename"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="TextView"
android:layout_weight="1"
android:gravity="center"
/>
<TextView
android:id="@+id/txtdefinition"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="TextView"
android:gravity="center"
android:layout_weight="1"
/>
填充我的列表视图的代码
final ArrayList<HashMap<String, String>> feedList = new ArrayList<HashMap<String, String>>();public void viewall() {
HashMap<String, String> map = new HashMap<String, String>();
Cursor c = db.rawQuery("SELECT * FROM tblwords", null);
if (c.getCount() == 0) {
}
while (c.moveToNext()) {
map = new HashMap<String, String>();
map.put("stringid", c.getString(0));
map.put("stringwords", c.getString(1));
map.put("stringvideofilename", c.getString(2));
map.put("stringdefinition", c.getString(3));
feedList.add(map);
}//while
}
simpleAdapter = new SimpleAdapter(this, feedList, R.layout.view_item, new String[]{"stringid", "stringwords", "stringvideofilename", "stringdefinition"}, new int[]{R.id.txtid, R.id.txtwords, R.id.txtvideofilename, R.id.txtdefinition});
lv.setAdapter(simpleAdapter);