我在我的应用中使用listview过滤器时遇到了问题。在KartyListFragment.java中,我声明:
ListAdapter adapter = new SimpleCursorAdapter(ctx,
R.layout.karty_list_item, db.getKarty(), from, to, 0);
现在在StartActivity.java中,在OnCreate方法中,我有EditText和TextWatcher。
EditText searchInput = (EditText) findViewById(R.id.search_edit_text);
watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
KartyListFragment.this.adapter.getFilter().filter(s); //THIS ROW IS WRONG
//it doesn't know getFilter()
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) { }
@Override
public void afterTextChanged(Editable s) { }
};
searchInput.addTextChangedListener(watcher);
在OnTextChanged方法中,我需要调用适配器的getFilter()方法,但它写错了。我读了一些教程。使用的是ArrayAdapters,我使用的是List (游标)。你有什么想法吗?
发布于 2013-02-23 23:43:55
将适配器从ListAdapter
更改为CursorAdapter
。ListAdapter
没有实现'getFilter`方法,顺便说一句,你需要实现一个QueryFilterProvider来在后台运行你的查询,并对列表进行实际的过滤。
发布于 2014-10-03 16:54:41
将ListAdapter
更改为SimpleAdapter
这是我的工作:) SimpleAdapter
有getFilter
方法
https://stackoverflow.com/questions/15042237
复制相似问题