我将列表视图及其适配器存储为全局变量。我不是通过扩展来创建我的列表ListActivity
。我的代码如下:
public void onCreate(Bundle...) {
mListView = (ListView) findViewById(R.id.listview1);
//setting my custom array adapter...works fine.
//also my custom adapter implements Filterable interface
mListView.setAdapter(...)
mListView.setTextFilterEnabled(true);
//My edit text where I enter my query
mSearchEditText = (EditText) findViewById(R.id.searchEditText);
mSearchEditText.addTextChangedLIstener(myListener);
}
private TextWatcher myListener = new TextWatcher () {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s == null || s.length() == 0) {
mListView.clearTextFilter();
}
else {
mListView.setFilterText(s.toString());
}
}
...
...
}
我的问题是当我在编辑文本中输入我的字符串时,它会在我的列表中给我正确的可用搜索项(只有数字),而不是项目本身。
例如,如果我的列表中有项目aa、bb、cc、dd、ff、ee、ee
因此,如果我搜索ee,我的结果将是aa, bb而不是ee, ee。如果我搜索cc,我的过滤器列表将只显示aa。
谁可以帮我这个事?