title: How can I set Search Bar in list view using custom adapter?
body: <p>I want to add search bar in a list view using adapter class can anybody help me below is my code.
  this is adapter class that I am using.
  Cat_Headers_Home_Adapter.java</p>
  
  <pre><code>        public class Cat_Headers_Home_Adapter extends SectionAdapter {
  
  
          private Activity cntx;
          private List&lt;Categories&gt; categoriesList;
           private List&lt;CatHeaders&gt; categoriesHeadersList;
  
         public Cat_Headers_Home_Adapter(Activity cntx,List&lt;Categories&gt;categoriesList, List&lt;CatHeaders&gt; categoriesHeadersList) {
  
          this.cntx = cntx;
          this.categoriesList = categoriesList;
          this.categoriesHeadersList = categoriesHeadersList;
  
      }
  
      @Override
      public int numberOfSections() {
          return categoriesHeadersList.size();
      }
  
      @Override
      public int numberOfRows(int section) {
          return categoriesList.size();
      }
  
      @Override
      public Object getRowItem(int section, int row) {
          return null;
      }
  
      @Override
      public boolean hasSectionHeaderView(int section) {
          return true;
      }
  
      @Override
      public View getRowView(int section, int row, View convertView, ViewGroup parent) {
          View view = convertView;
          Holder holder;
          if (view == null) {
              LayoutInflater inflater = (LayoutInflater) cntx
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              view = inflater.inflate(R.layout.adapter_home_service_cat, null);
              holder = new Holder();
              view.setTag(holder);
          } else {
              holder = (Holder) view.getTag();
          }
  
          Categories categories = categoriesList.get(section);
          holder.service_name = (TextView) view.findViewById(R.id.service_name);
          holder.count = (TextView) view.findViewById(R.id.total);
          holder.service_icon = (ImageView) view.findViewById(R.id.service_icon);
          holder.service_layout =    (LinearLayout)view.findViewById(R.id.service_layout);
          holder.service_name.setText(categories.catName);
          holder.count.setText(categories.count);
          holder.service_icon.setImageResource(categories.catImage);
          holder.service_layout.setVisibility(View.VISIBLE);
          return view;
      }
  
      private class Holder {
          TextView service_name;
          TextView count;
          ImageView service_icon;
          LinearLayout service_layout;
      }
  
      @Override
      public int getSectionHeaderViewTypeCount() {
          return 2;
      }
  
      @Override
      public int getSectionHeaderItemViewType(int section) {
          return section % 2;
      }
  
      @Override
      public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
  
          if (convertView == null) {
  
              convertView = (TextView) cntx.getLayoutInflater().inflate(cntx.getResources().getLayout(android.R.layout.simple_list_item_1), null);
  
          }
  
  
          ((TextView) convertView).setText(categoriesHeadersList.get(section).catName);
          ((TextView) convertView).setTextColor(cntx.getResources().getColor(android.R.color.white));
          convertView.setBackgroundColor(cntx.getResources().getColor(R.color.red));
          return convertView;
      }
  
      @Override
      public void onRowItemClick(AdapterView&lt;?&gt; parent, View view, int section, int row, long id) {
          super.onRowItemClick(parent, view, section, row, id);
          Toast.makeText(cntx, "Section " + section + " Row " + row, Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>this is a class i want to add a search bar on it<br>
  Home_fragment.java</p>
  
  <pre><code>    public class Home_Fragment extends Fragment {
      private HeaderListView list;
      private EditText searchBar;
      private int[] images;
      private String[] array;
      private String[] headers;
      private String[] fake_count;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; listView;
  
  
      private List&lt;Categories&gt; categoriesList = new ArrayList&lt;&gt;();
      private List&lt;CatHeaders&gt; categoriesListHeader = new ArrayList&lt;&gt;();
  
      public static Home_Fragment newInstance(int index) {
          Home_Fragment f = new Home_Fragment();
  
          // Supply index input as an argument.
          Bundle args = new Bundle();
          args.putInt("position", index);
          f.setArguments(args);
  
          return f;
      }
  
      public int getShownIndex() {
          return getArguments().getInt("index", 0);
      }
  
      public Home_Fragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          listView = new ArrayList&lt;&gt;();
         images = Utils.getResourcesImages();
      //    images = getActivity().getResources().getIntArray(R.array.service_images_for_list_headers);
          array = getActivity().getResources().getStringArray(R.array.services);
          headers = getActivity().getResources().getStringArray(R.array.header_title);
          fake_count = getActivity().getResources().getStringArray(R.array.fake_count);
  
          for (int a = 0; a &lt; images.length; a++) {
  
              int imageId = images[a];
              String count = fake_count[a];
              String name = array[a];
  
              Categories categoriesObj;
  
              if (a == 0 || a == 29 || a == 36 || a == 42 || a == 53) {
                  categoriesObj = new Categories(name, imageId, count, true);
              } else {
                  categoriesObj = new Categories(name, imageId, count, false);
              }
  
              categoriesList.add(categoriesObj);
  
          }
  
          for (int a = 0; a &lt; headers.length; a++) {
  
              CatHeaders categoriesObj;
  
                  categoriesObj = new CatHeaders(headers[a]);
  
  
              categoriesListHeader.add(categoriesObj);
  
          }
  
  
          Log.d("HOME Message Fragment", "Home Message Fragment");
  
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View rootView = inflater.inflate(R.layout.fragment_home, container, false);
          list = (HeaderListView) rootView.findViewById(R.id.list_view);
  
  
  
  
  
  
          searchBar = (EditText) rootView.findViewById(R.id.search_field);
          searchBar.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
                  if (s.length() &gt; 2) {
                      searchServiceFromList(s.toString());
                  } else {
                      setOldView();
                  }
              }
  
          });
  
  
          Arrays.sort(array);
          listView.clear();
          for (int i = 0; i &lt; array.length; i++) {
              HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
              map.put("service_name", array[i]);
              map.put("icon_position", Integer.toString(i));
              map.put("count", fake_count[i]);
              listView.add(map);
          }
  
          Cat_Headers_Home_Adapter adapter = new Cat_Headers_Home_Adapter(getActivity(),categoriesList,categoriesListHeader);
          list.setAdapter(adapter);
  //        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  //            @Override
  //            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  //                HashMap&lt;String, String&gt; map = listView.get(position);
  //                //  Toast.makeText(getActivity(), map.get("service_name").toString(), Toast.LENGTH_SHORT).show();
  //                //  objBook.show();
  //                //  objBook.setService(map.get("service_name").toString());
  //              /*  Post_New_Job_Fragment fragment = new Post_New_Job_Fragment();
  //                Bundle bundle = new Bundle();
  //                bundle.putString("service_name", map.get("service_name").toString());
  //                fragment.setArguments(bundle);
  //                final FragmentTransaction ft = getFragmentManager().beginTransaction();
  //                ft.replace(R.id.container, fragment, "NewFragmentTag");
  //                ft.addToBackStack(null);
  //                ft.commit();*/
  //                Intent i = new Intent(getActivity(), Post_New_Job_Activity.class);
  //                i.putExtra("service_name", map.get("service_name").toString());
  //                i.putExtra("icon_position", map.get("icon_position").toString());
  //                getActivity().startActivityForResult(i, 200);
  //
  //
  //            }
  //        });
          return rootView;
      }
  
      @Override
      public void startActivityForResult(Intent intent, int requestCode) {
          super.startActivityForResult(intent, requestCode);
  
      }
  
      public void searchServiceFromList(String s) {
  //        ArrayList&lt;HashMap&lt;String, String&gt;&gt; tempList = new ArrayList&lt;&gt;();
  //        for (int i = 0; i &lt; listView.size(); i++) {
  //            HashMap&lt;String, String&gt; map = listView.get(i);
  //            if ((map.get("service_name").toString().toLowerCase()).contains(s.toLowerCase())) {
  //                tempList.add(map);
  //            }
  //        }
  //
  //        Home_Adapter adapter = new Home_Adapter(getActivity(), tempList, images);
  //        list.setAdapter(adapter);
      }`enter code here`
  
      public void setOldView() {
  //        Home_Adapter adapter = new Home_Adapter(getActivity(), listView, images);
  //        list.setAdapter(adapter);
      }
  }`enter code here`
  </code></pre>