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);
}
答案 0 :(得分:0)
简单的简短回答是您必须延长ListActivity
而不是Actity
因为我面临同样的问题,我的提示参考是
The method setListAdapter(ArrayAdapter) is undefined for the type ReminderListActivity