【发布时间】:2010-10-25 20:25:06
【问题描述】:
我的列表视图上的过滤器有问题。 事实上,IndexAdapter 可以很好地工作,但 SimpleCursorAdapter 则不行。
在下面的例子中,如果 isCursor==false,过滤器工作得很好 但如果是== true,则过滤器不起作用!
顺便说一句,适配器工作得很好。
if(isCursor){
mCursorAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1, stationsCursor, columns, to);
FilterTextWatcherCursor filterTextWatcher = new FilterTextWatcherCursor(mCursorAdapter);
filterText.addTextChangedListener(filterTextWatcher);
this.setListAdapter(mCursorAdapter);
}
else{
mIndexAdapter = new MyIndexAdapter<String>(getApplicationContext(),
R.layout.row_station_picker, elements);
FilterTextWatcher filterTextWatcher = new FilterTextWatcher(mIndexAdapter);
filterText.addTextChangedListener(filterTextWatcher);
this.setListAdapter(mIndexAdapter);
}
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setFastScrollEnabled(true);
我真的不明白问题可能出在哪里。 有关信息,我的 FilterTextWatcher 是:
public class FilterTextWatcherCursor implements TextWatcher {
private SimpleCursorAdapter adapter;
public FilterTextWatcherCursor(SimpleCursorAdapter adapter) {
this.adapter = adapter;
}
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);
}
}
FilterTextWatcher 大同小异,不过我把 SimpleCursorAdapter 换成了 IndexAdapter
非常感谢您的帮助...
【问题讨论】:
-
刚找到一个类似的问题,但是我没看懂答案!stackoverflow.com/questions/2002607/…
标签: android listview text filter