如何实现过滤搜索/列表视图搜索?

时间:2012-08-15 12:34:04

标签: android android-listview

如何利用当前ListView与我的搜索集成?

/** 
 * Updating parsed JSON data into ListView 
 * */
ListAdapter adapter = new SimpleAdapter( 
AllEventsActivity.this, eventsList, R.layout.list_item, new String[] { TAG_EID, _NAME}, 
new int[] { R.id.eid, R.id.ename }); 

//updating listview 
setListAdapter(adapter);

现在如何使用ListView集成到我的搜索代码中?

public void onTextChanged(CharSequence s, int start, int before, int count)
{
    textlength = et.getText().length();
    array_sort.clear();
    for (int i = 0; i < listview_array.length; i++) {
        if (textlength <= listview_array[i].length()) {
            if(et.getText().toString().equalsIgnoreCase((String)
                             listview_array[i].subSequence(0, textlength)))
            {
                array_sort.add(listview_array[i]);
            }
        }
    }

    lv.setAdapter(new ArrayAdapter<String>(ListViewSearchExample.this,android.R.layout.simple_list_item_1, array_sort));
}

1 个答案:

答案 0 :(得分:0)

你似乎总想念的是:

将您的适配器声明为变量并调用:

adapter.notifyDataSetChanged();