Hello! I have a grid view with the row model having a image view and text view in it. I set a custom adapter to populate the the grid view with images and texts successfully.
But now I want to use a search view to filter the grid view on the base of text in text views. For this I implemented Filterable interface .
When i enter the string in my search view nothing happens. I am pasting my code also. Please check it . All the code is in one class.

Please view the code in the inner classes ImageAdapter and CustomerFilter specially. I have searched on internet for this problem, but by problem not solved. Please guide me what mistake i am doing?

package com.example.hp430.tabsexample;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

import java.util.ArrayList;
import java.util.zip.Inflater;

import static com.example.hp430.tabsexample.MainActivity.MYPREF;
import static com.example.hp430.tabsexample.MainActivity.gridname;

public class TabFragment1 extends android.support.v4.app.Fragment {
    private AdView adView;
    SharedPreferences sharedpreferences;

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup `container, Bundle savedInstanceState) {`
View rootview = inflater.inflate(R.layout.tab_fragment_1,container,false);
SearchView sv = rootview.findViewById(R.id.searchview1);
GridView gridview = (GridView)rootview.findViewById(R.id.pfgrid);

  gridview.setAdapter(new ImageAdapter(getActivity()));

    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        public boolean onQueryTextSubmit(String query) {
            return false;

        public boolean onQueryTextChange(String newText) {
           new ImageAdapter(getActivity()).getFilter().filter(newText);
            return false;

    adView = rootview.findViewById(R.id.ad_view 
    gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            sharedpreferences = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
            String n = sharedpreferences.getString(gridname,"namekey");
           // Toast.makeText(getContext(),n,Toast.LENGTH_SHORT).show();
           Intent i = new Intent(getActivity(),WebViewActivity.class);
    // Inflate the layout for this fragment
    return rootview;

public void onAttach(Context context) {


public void onCreate(@Nullable Bundle savedInstanceState) {


public void onPause() {
    if (adView != null) {

public void onResume() {
    if (adView != null) {

    // Inner Class ImageAdapter  in class TabFragment1
public class ImageAdapter extends BaseAdapter implements Filterable{

    private Context mContext;
    // Constructor
    public ImageAdapter(Context c) {
        mContext = c;

    public int getCount() {
        return mThumbIds.length;

    public Object getItem(int position) {
        return null;

    public long getItemId(int position) {
        return 0;

    public View getView(int position, View convertView, ViewGroup parent) {

        ImageView imageView;

        TextView txt;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null ) {

            convertView = inflater.inflate(R.layout.row_grid, parent, false);

        imageView = convertView.findViewById(R.id.mimageView);
        txt = convertView.findViewById(R.id.mtextView);

        ViewGroup.LayoutParams lp = imageView.getLayoutParams();
        lp.width = 170;
        lp.height = 170;

        imageView.setPadding(8, 8, 8, 8);


        return convertView;

    public Integer[] mThumbIds = {

    public String[] mThumbNames = {
            "Alkaram", "Khaadi","DeepakPerwani", "HSY","Chenone","Mari.b","Warda","Firdous","SanaSafinaz",
            "Sapphire","Kayseria","Junaid Jamshaid","Bareeze","Gul Ahmad","CrossStich","NishatLinen"


    public Filter getFilter() {
       Filter filter=null;
            filter = new CustomFilter();
        return filter;

    //Inner class CustomeFilter  in class ImageAdapter
    class CustomFilter extends Filter{
        ArrayList Filterlist = new ArrayList();
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();
            if(constraint !=null && constraint.length()>0){

                constraint = constraint.toString().toUpperCase();

                for(int i=0;i<mThumbNames.length;i++){
                        int image = mThumbIds[i];
                        String name = mThumbNames[i];



                results.count = Filterlist.size();
                results.values =Filterlist;
                Toast.makeText(getActivity(),"count= "+Filterlist.size(),Toast.LENGTH_LONG).show();


                results.count = Filterlist.size();
                results.values =Filterlist;

            return results;

        protected void publishResults(CharSequence constraint, FilterResults results) {
            Filterlist = (ArrayList ) results.values;
    }// end class CustomFilter

   }//end  class ImageAdapter

}// end parent class i-e TabFragment1