1

尝试在列表视图中实现搜索功能在搜索中有问题,在这里我将代码放置在出现错误的地方

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

1 回答 1

1

似乎FriendsActivity.this.adapter有 type 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

于 2013-01-17T14:37:17.757 回答