1

adapter.getFilter().filter(s);嗨,我仔细研究了如何实现过滤器搜索,但我仍然无法让我的工作。目前我正在使用带有 hashmap 的 listadapter 来显示 listview。现在我如何使用 listadapter 来做搜索功能?下面是我的代码:

private ListAdapter adapter;
ArrayList<HashMap<String, String>> eventsList;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
      setContentView(R.layout.homepage);
      searchBar.addTextChangedListener(filterTextWatcher);

// HashMap for ListView
eventsList = new ArrayList<HashMap<String, String>>();
adapter = new SimpleAdapter(HomepageActivity.this, eventsList,
R.layout.list_event, new String[] { TAG_EID, TAG_ENAME, TAG_CNAME, TAG_CREATED_AT },
new int[] { R.id.eid, R.id.ename, R.id.cname, R.id.created_at });

// updating listView
setListAdapter(adapter);
}
private TextWatcher filterTextWatcher = new TextWatcher() { 

    public void afterTextChanged(Editable s) { 
    } 

    public void beforeTextChanged(CharSequence s, int start, int count, 
            int after) { 
    } 

    public void onTextChanged(CharSequence s, int start, int before, 
            int count) { 
        adapter.getFilter().filter(s);<--- THIS IS WHERE I GOT ERROR
    } 

}; 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    searchBar.removeTextChangedListener(filterTextWatcher); 
}
4

1 回答 1

0

ListActivity简单的简短答案是你不能扩展Actity ,因为我遇到了同样的问题,我的提示参考是

未为 ReminderListActivity 类型定义方法 setListAdapter(ArrayAdapter)

于 2012-12-21T17:39:20.560 回答