How to implement getFilter on a BaseAdapter?

前端 未结 7 851
半阙折子戏
半阙折子戏 2020-12-06 03:55

I am trying to implement a getFilter() on a base adapter to filter out search results on a List. Is there any example of how to implement a getFilter()?

MainActivity

7条回答
  •  忘掉有多难
    2020-12-06 04:27

    in your adapter put this class to use it in getfilter method

    //this is a simple class that filtering the ArrayList of strings used in adapter
    
    public class filter_here extends Filter{
    
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                // TODO Auto-generated method stub
    
                FilterResults Result = new FilterResults();
                // if constraint is empty return the original names
                if(constraint.length() == 0 ){
                    Result.values = Original_Names;
                    Result.count = Original_Names.size();
                    return Result;
                }
    
                ArrayList Filtered_Names = new ArrayList();
                String filterString = constraint.toString().toLowerCase();
                String filterableString;
    
                for(int i = 0; i) results.values;
                notifyDataSetChanged();
            }
    
        }
    

    return instance from it in getfilter

    @Override
        public Filter getFilter() {
            // TODO Auto-generated method stub
            return filter;
        }
    

    full example

提交回复
热议问题