gpt4 book ai didi

android - 错误 : The method getFilter() is undefined for the type FriendsActivity. ListAdapter

转载 作者:行者123 更新时间:2023-11-30 03:49:32 26 4
gpt4 key购买 nike

尝试在搜索中遇到问题的 ListView 中实现搜索功能,这里我将代码放在出现错误的地方

 friendsearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
FriendsActivity.this.adapter.getFilter().filter(cs);
//*in the above line i am getting error.*
}

public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});

最佳答案

似乎 FriendsActivity.this.adapter 的类型是 ListAdapter。如果它实际上是数组适配器,那么尝试:

((ArrayAdapter<?>) FriendsActivity.this.adapter).getFilter().filter(cs)

编辑:

您的源代码中有以下类:class ListAdapter extends BaseAdapter。 BaseAdapter 没有实现过滤器。所以你需要手动实现它。查看本教程:http://www.survivingwithandroid.com/2012/10/android-listview-custom-filter-and.html

关于android - 错误 : The method getFilter() is undefined for the type FriendsActivity. ListAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14381316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com