title: I need action bar search view in a custom adapter listview
body: <p>In my app, there is a listview with textview and image, I can search element by adding a edittext in xml, but I want search bar in action bar.. how can I do this? please help..
      <a href="https://i.stack.imgur.com/E2cPX.png" rel="nofollow noreferrer">Image: </a></p>
  
  <pre><code>      // My activity java code
  
  productName = new String[] { "Baby Item", "Harbal Item", "Medicine Item", "Electronics Item", "Product item 1",
          "Product item 2", "Product item 3", "Product item 4", "Product item 5", "Product item 6"};
  
  productDescesc = new String[] { "Baby Item description", "Harbal Item description",
          "Medicine Item description", "Electronics Item description", "Product item description",
          "Product item description", "Product item description", "Product item description", "Product item description","Product item description" };
  
      productIcon = new int[] { R.drawable.baby_item, R.drawable.harbal_item,
              R.drawable.medicine_item, R.drawable.electronics_item,
              R.drawable.demo_product_item, R.drawable.demo_product_item, R.drawable.demo_product_item,
              R.drawable.demo_product_item, R.drawable.demo_product_item, R.drawable.demo_product_item };
  
      // Locate the ListView in listview_main.xml
      list = (ListView) findViewById(R.id.list);
  
      for (int i = 0; i &lt; productName.length; i++)
      {
          SearchProduct searchProduct = new SearchProduct(productIcon[i], productName[i], productDescesc[i]);
          // Binds all strings into an array
          arraylist.add(searchProduct);
      }
  
      // Pass results to ListViewAdapter Class
      adapter = new ListViewAdapter(this, arraylist);
  
      // Binds the Adapter to the ListView
      list.setAdapter(adapter);
  
      // Locate the EditText in listview_main.xml
      editsearch = (EditText) findViewById(R.id.search);
  
      // Capture Text in EditText
      editsearch.addTextChangedListener(new TextWatcher() {
  
          @Override
          public void afterTextChanged(Editable arg0) {
              // TODO Auto-generated method stub
              String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
              adapter.filter(text);
          }
  
          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1,
                                        int arg2, int arg3) {
              // TODO Auto-generated method stub
          }
  
          @Override
          public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                                    int arg3) {
              // TODO Auto-generated method stub
          }
  
  
          });
  
          //Onclick
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View v, final int position, long id) {
  
  //                                Toast.makeText(Search.this,"List Item Clicked:" + position, Toast.LENGTH_SHORT)
  //                        .show();
                  Intent intent=new Intent(Search.this,ProductActivity.class);
                  startActivity(intent);
  
              }
          });
  </code></pre>
  
  <p>//my custom adapter code</p>
  
  <pre><code>public class ListViewAdapter extends BaseAdapter {
  
      // Declare Variables
      Context mContext;
      LayoutInflater inflater;
      private List&lt;SearchProduct&gt; productList = null;
      private ArrayList&lt;SearchProduct&gt; arraylist;
      SearchProduct searchProduct;
      private ListViewAdapter filter;
  
      public ListViewAdapter(Context context,
                             List&lt;SearchProduct&gt; worldpopulationlist) {
          mContext = context;
          this.productList = worldpopulationlist;
          inflater = LayoutInflater.from(mContext);
          this.arraylist = new ArrayList&lt;SearchProduct&gt;();
          this.arraylist.addAll(worldpopulationlist);
      }
  
      public class ViewHolder {
          ImageView icon;
          TextView name;
          TextView desc;
      }
  
      @Override
      public int getCount() {
          return productList.size();
      }
  
      @Override
      public SearchProduct getItem(int position) {
          return productList.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(final int position, View view, ViewGroup parent) {
          final ViewHolder holder;
          if (view == null) {
              holder = new ViewHolder();
              view = inflater.inflate(R.layout.search_list_item, null);
  
              // Locate the TextViews in listview_item.xml
              holder.icon = (ImageView) view.findViewById(R.id.imgProduct);
              holder.name = (TextView) view.findViewById(R.id.tvProductName);
              holder.desc = (TextView) view.findViewById(R.id.tvDesc);
              // Locate the ImageView in listview_item.xml
  
              view.setTag(holder);
          } else {
              holder = (ViewHolder) view.getTag();
          }
          // Set the results into TextViews
          holder.name.setText(productList.get(position).getName());
          holder.desc.setText(productList.get(position).getDesc());
  
          // Set the results into ImageView
          holder.icon.setImageResource(productList.get(position)
                  .getIcon());
  
          return view;
      }
  
      // Filter Class
      public void filter(String charText) {
          charText = charText.toLowerCase(Locale.getDefault());
          productList.clear();
          if (charText.length() == 0) {
              productList.addAll(arraylist);
          } else {
              for (SearchProduct searchProduct : arraylist) {
                  if (searchProduct.getName().toLowerCase(Locale.getDefault())
                          .contains(charText)) {
                      productList.add(searchProduct);
                  }
              }
          }
          notifyDataSetChanged();
      }
  
  }
  </code></pre>