我想过滤ListView
,以便在用户键入EditText
(ListView
项目中发生的)中的字/字符串时,应筛选该项目。使用子字符串搜索筛选ListView
在下面的代码中,EditText
从首字符检查项目名称。我不需要那个。
对于如:
列表项:萨钦,多尼,俞拉吉......
的EditText:v ......
搜索结果应该显示我俞拉吉
这里是我的代码:
public void onTextChanged(CharSequence s, int start, int before, int count) {
textlength = editText.getText().length();
text_sort.clear();
image_sort.clear();
for (int i = 0; i < names.length; i++) {
if (textlength <= names[i].length()) {
if (editText.getText().toString().equalsIgnoreCase((String)names[i].subSequence(0,textlength))) {
text_sort.add(names[i]);
image_sort.add(imageid[i]);
}
}
}
listView.setAdapter(new MyCustomAdapter(text_sort, image_sort));
}
参阅:http://www.androidbegin.com/tutorial/android-search-listview-using-filter/ – Kathi
[列表视图过滤器(http://stackoverflow.com/questions/24769257/custom-listview-adapter-with-filter-android)检查这个答案。它可以帮助 – skydroid
@kathi ...我更新了我的代码,请亲切看看....并且我也了解了代码链接 – Devk