public void initFilter ( FunDapterFilter < T > filter ) { if ( filter == null ) throw new IllegalArgumentException ( "Cannot pass a null filter to FunDapter" ) ; this . funDapterFilter = filter ; mFilter = new Filter ( ) { @ Override protected void publishResults ( CharSequence constraint , FilterResults results ) { @ SuppressWarnings ( "unchecked" ) List < T > list = ( List < T > ) results . values ; if ( results . count == 0 ) { resetData ( ) ; } else { mDataItems = list ; } notifyDataSetChanged ( ) ; } @ Override protected FilterResults performFiltering ( CharSequence constraint ) { FilterResults results = new FilterResults ( ) ; if ( constraint == null || constraint . length ( ) == 0 ) { // No constraint - no point in filtering. results . values = mOrigDataItems ; results . count = mOrigDataItems . size ( ) ; } else { // Perform the filtering operation List < T > filter = funDapterFilter . filter ( constraint . toString ( ) , mOrigDataItems ) ; results . count = filter . size ( ) ; results . values = filter ; } return results ; } } ; }
Use this method to enable filtering in the adapter .