在一列上使用listview搜索的TextWatcher?

时间:2017-07-03 10:27:36

标签: android listview search textwatcher

我想搜索listView中有4列的特定列。 也许我只是想搜索"单词"列。

Screenshot

不知何故,textwatcher还会过滤所有列

enter image description here

这是我的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);

0 个答案:

没有答案