title: Searchview Filters, from retrieved Volley Library data
body: <p>I am using <code>Volley Library</code> for retrieving data from server. Now I implemented <code>SearchView</code> for filter the data. Here I used searchview for each and every <code>tabs</code>. Search query is not properly passed to adapter class.Sometimes it passes.While it pass to adapter class I need to filter the data which was retrieved from Server and need to adapt it the recycler view.</p>
  
  <p>This is my code..Please help me to fix it.</p>
  
  <p><strong>TabFragment.java</strong></p>
  
  <pre><code>public class TabFragment_1 extends Fragment implements SearchView.OnQueryTextListener, SearchView.OnCloseListener {
  
      public static final String MyPREFERENCES = "Preference";
      Context context;
      RecyclerView recyclerView;
      SharedPreferences pref;
      String currentTab;
      private String query = "";
      //    private ListAdapter mAdapter;
      private List&lt;Restaurant_Beam&gt; listSuperHeroes;
      private RecyclerView.LayoutManager layoutManager;
      private RecyclerView.Adapter adapter;
      private int count = 0;
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment, container, false);
          context = getActivity();
          pref = context.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
          currentTab = pref.getString("FIRST_TAB", "tab1");
          Log.e("Current Tab", currentTab);
  
          recyclerView = (RecyclerView) view.findViewById(R.id.fragment_list_rv);
  
          layoutManager = new GridLayoutManager(context, 2);
          recyclerView.setLayoutManager(layoutManager);
          recyclerView.setHasFixedSize(true);
          setHasOptionsMenu(true);
  
          listSuperHeroes = new ArrayList&lt;&gt;();
  
          getData();
          return view;
      }
  
      //This method will get data from the web api
      private void getData() {
          //Showing a progress dialog
          final ProgressDialog loading = ProgressDialog.show(context, "Loading Data", "Please wait...", false, false);
          //Creating a json array request
          JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config.DATA_URL, new Response.Listener&lt;JSONArray&gt;() {
  
              @Override
              public void onResponse(JSONArray response) {
                  //Dismissing progress dialog
                  loading.dismiss();
                  //calling method to parse json array
                  parseData(response);
              }
          },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                      }
                  });
  
          //Creating request queue
          RequestQueue requestQueue = Volley.newRequestQueue(context);
  
          //Adding request to the queue
          requestQueue.add(jsonArrayRequest);
      }
  
      private void parseData(JSONArray array) {
  
          for (int i = 0; i &lt; array.length(); i++) {
              Restaurant_Beam superHero = new Restaurant_Beam();
              JSONObject json = null;
              try {
                  json = array.getJSONObject(i);
                  superHero.setStr_categoryName(json.getString(Config.CATEGORY_NAME));
                  superHero.setStr_productName(json.getString(Config.PRODUCT_NAME));
                  superHero.setStrPrice(json.getInt(String.valueOf(Config.PRICE)));
                  superHero.setImageUrl(json.getString(Config.TAG_IMAGE_URL));
                  superHero.setTAB_NAME(json.getString(Config.TAB_NAME));
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              if (superHero.getTAB_NAME().contains(currentTab)) {
                  listSuperHeroes.add(superHero);
                  adapter = new CardAdapter(listSuperHeroes, context);
                  recyclerView.setAdapter(adapter);
              }
          }
      }
  
      @Override
      public boolean onClose() {
          System.out.println("Restaurant Tab onQueryTextSubmit =" + "");
          return false;
      }
  
      @Override
      public boolean onQueryTextSubmit(String query) {
          System.out.println("Restaurant Tab onQueryTextSubmit =" + query);
          ((CardAdapter) recyclerView.getAdapter()).setFilter(query);
          return true;
      }
  
      @Override
      public boolean onQueryTextChange(String newText) {
          System.out.println("Restaurant Tab onQueryTextSubmit =" + newText);
  
          return false;
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          inflater.inflate(R.menu.main, menu);
  
          final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
          SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
          searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
          searchView.setSubmitButtonEnabled(false);
          searchView.setIconifiedByDefault(true);
          searchView.setOnQueryTextListener(this);
          searchView.setOnCloseListener(this);
          super.onCreateOptionsMenu(menu, inflater);
      }
  }
  </code></pre>
  
  <p><strong>CardAdapter.java:</strong></p>
  
  <pre><code>public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
  
      List&lt;Restaurant_Beam&gt; restaurant_prducts;
      Config config;
      Bitmap bmp;
      boolean success = false;
      ArrayList&lt;String&gt; CATEGORYNAME;
      ArrayList&lt;String&gt; ITEMNAME;
      ArrayList&lt;String&gt; ITEM_PRICE;
      ViewHolder vHolder;
      ArrayList&lt;String&gt; visibleObjects;
      ArrayList&lt;String&gt; wordList;
  
      private ImageLoader imageLoader;
      private Context context;
  
      public CardAdapter(List&lt;Restaurant_Beam&gt; superHeroes, Context context) {
          super();
  
          this.restaurant_prducts = superHeroes;
          this.context = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
          ViewHolder viewHolder = new ViewHolder(v);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(final ViewHolder holder, final int position) {
  
          Restaurant_Beam restaurant_beam = restaurant_prducts.get(position);
  
          imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
          imageLoader.get(config.IMAGE_URL + restaurant_beam.getImageUrl() + ".jpg", ImageLoader.getImageListener(holder.productImage, R.drawable.image_1, R.drawable.image_1));  //android.R.drawable.ic_dialog_alert
  
  /*        holder.productImage.setImageUrl(config.IMAGE_URL + restaurant_beam.getImageUrl() + ".jpg", imageLoader);
          holder.txt_itemName.setText(restaurant_beam.getStr_productName());
          holder.txt_categoryName.setText(String.valueOf(restaurant_beam.getStr_categoryName()));
          holder.txt_Price.setText(String.valueOf(restaurant_beam.getStrPrice()));
          holder.linearLayout.setVisibility(View.INVISIBLE);*/
  
          String IMAGE_URL = config.IMAGE_URL + restaurant_beam.getImageUrl() + ".jpg";
          String ITEM_NAME = restaurant_beam.getStr_productName();
          String CATEGORY_NAME = restaurant_beam.getStr_categoryName();
          String PRICE = String.valueOf(restaurant_beam.getStrPrice());
  
          holder.productImage.setImageUrl(IMAGE_URL, imageLoader);
          holder.txt_itemName.setText(ITEM_NAME);
          holder.txt_categoryName.setText(CATEGORY_NAME);
          holder.txt_Price.setText(PRICE);
          holder.linearLayout.setVisibility(View.INVISIBLE);
  
          ITEMNAME = new ArrayList&lt;&gt;();
          CATEGORYNAME = new ArrayList&lt;&gt;();
          ITEM_PRICE = new ArrayList&lt;&gt;();
  
          ITEMNAME.add(ITEM_NAME);
          CATEGORYNAME.add(CATEGORY_NAME);
          ITEM_PRICE.add(PRICE);
  
          Log.e("Filter", String.valueOf(ITEMNAME) + "  ..." + CATEGORYNAME);
  
          holder.productImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent i = new Intent(view.getContext(), ProductActivity.class);
                  i.putExtra("itemName", holder.txt_itemName.getText().toString());
                  i.putExtra("categoryName", holder.txt_categoryName.getText().toString());
                  i.putExtra("Price", Integer.parseInt(holder.txt_Price.getText().toString()));
                  view.getContext().startActivity(i);
              }
          });
  
          holder.iv_settings.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  holder.linearLayout.setVisibility(View.VISIBLE);
              }
          });
          holder.viewDetail.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(v.getContext(), "Clicked ViewDetail", Toast.LENGTH_SHORT).show();
              }
          });
          holder.addToCart.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(v.getContext(), "Clicked AddToCart", Toast.LENGTH_SHORT).show();
              }
          });
          holder.checkOut.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(v.getContext(), "Clicked CheckOut", Toast.LENGTH_SHORT).show();
              }
          });
      }
  
      @Override
      public int getItemCount() {
          Log.e("Restaurant Size", String.valueOf(restaurant_prducts
                  .size()));
          return restaurant_prducts.size();
      }
  
      public void setFilter(String query) {
          Log.e("Adapter Query", query);
          String[] stringArray = new String[restaurant_prducts.size()];
          for (int i = 0; i &lt; restaurant_prducts.size(); i++) {
              System.out.println("I am inside ForLoop" + " " + i);
              stringArray[i] = restaurant_prducts.get(i).toString();
          }
          wordList = new ArrayList&lt;String&gt;(Arrays.asList(stringArray));
  
          List&lt;Restaurant_Beam&gt; list = new ArrayList&lt;&gt;(stringArray.length);
  
  //        list.addAll(wordList);
  //        restaurant_prducts.add(list);
  //
  //        for(String s : stringArray){
  //            restaurant_prducts.add()
  //        }
  
          Log.e("String array", wordList.toString());
  
          Log.e("Adapter Query", String.valueOf(ITEMNAME) + " " + CATEGORYNAME + " " + ITEM_PRICE + " " + stringArray);
          notifyDataSetChanged();
      }
  
  //    public void flushFilter() {
  //        visibleObjects=new ArrayList&lt;&gt;();
  //        visibleObjects.addAll(allObjects);
  //        notifyDataSetChanged();
  //    }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          public NetworkImageView productImage;
          public TextView txt_categoryName;
          public TextView txt_itemName, txt_Price;
          public CardView cardlist_item;
          public ImageView iv_settings;
          public LinearLayout linearLayout;
          public Button viewDetail, addToCart, checkOut;
  
          public ViewHolder(View itemView) {
              super(itemView);
              iv_settings = (ImageView) itemView.findViewById(R.id.iv_settings);
              cardlist_item = (CardView) itemView.findViewById(R.id.cardlist_item);
              txt_itemName = (TextView) itemView.findViewById(R.id.txt_itemName);
              txt_Price = (TextView) itemView.findViewById(R.id.txt_Price);
              txt_categoryName = (TextView) itemView.findViewById(R.id.txt_categoryName);
              productImage = (NetworkImageView) itemView.findViewById(R.id.productImage);
              linearLayout = (LinearLayout) itemView.findViewById(R.id.linearTransparent);
              viewDetail = (Button) itemView.findViewById(R.id.butViewDetail);
              addToCart = (Button) itemView.findViewById(R.id.but_addTCart);
              checkOut = (Button) itemView.findViewById(R.id.butCheckOut);
          }
      }
  }
  </code></pre>