Android 正在搜索使用ListAdapater而不是ArrayAdapter的ListView
我有一个列表视图,它使用列表适配器作为适配器来填充列表视图。我在网上研究了一种添加搜索的方法,但他们都在使用ArrayAdapter。因为我使用的是列表适配器,所以函数Android 正在搜索使用ListAdapater而不是ArrayAdapter的ListView,android,listview,search,android-arrayadapter,listadapter,Android,Listview,Search,Android Arrayadapter,Listadapter,我有一个列表视图,它使用列表适配器作为适配器来填充列表视图。我在网上研究了一种添加搜索的方法,但他们都在使用ArrayAdapter。因为我使用的是列表适配器,所以函数getFilter()不起作用。这是我的密码 inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequenc
getFilter()
不起作用。这是我的密码
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
有人能帮我找到一种简单的替代方法吗?在适配器中创建一个函数,如下所示:
公共空过滤器(字符串图表文本){
charText=charText.toLowerCase(Locale.getDefault());
objectList.clear();
如果(ChartText.length()==0){
addAll(objectAsArraylist);
}否则{
for(对象v:objectAsArraylist){
对象列表。添加(v);
}
}
notifyDataSetChanged();
}
其中,objectList
是传递给适配器的列表,objectAsArraylist
是传递给arraylist的objectList
然后您可以在onTextChanged
上调用此方法:
adapter.filter(text)
我没有arrayList。我有一个SimpleAdapter和一个ListAdapter。因此addAll()
和add()
函数不起作用。您可以创建一个函数,将列表中所需的值传递给arraylist。list objectAsArraylist=new arraylist()代码>objectAsArraylist.addAll(objectList)代码>我仍然搞不清楚如何实现你的编码你能在你的帖子中插入你的适配器代码以便我能澄清吗?