尝试在搜索中遇到问题的列表视图中实现搜索功能,这里我将代码放在我收到错误
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
}
});
答案 0 :(得分:1)
似乎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