错误:类型为FriendsActivity.ListAdapter的方法getFilter()未定义

时间:2013-01-17 14:31:34

标签: android

尝试在搜索中遇到问题的列表视图中实现搜索功能,这里我将代码放在我收到错误

 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
        }
    });

1 个答案:

答案 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