title: Implementing Google play and maps like Search Bar android
body: <p>I have a requirement to create a Google play and maps like search bar with filter in my project, but I have no idea how to start with. I tried it by own custom implementation like as follows:</p>
  
  <p><strong>Autocomplete TextView inside ToolBar android</strong></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>toolbar = (Toolbar) findViewById(R.id.tool_bar);
          setSupportActionBar (toolbar);
  
          ArrayList&lt;String&gt; searchArrayList = new ArrayList&lt;String&gt;();
  
          searchArrayList.add("United States");
          searchArrayList.add("France");
          searchArrayList.add("United Kingdom");
          searchArrayList.add("India");
          searchArrayList.add("Indonesia");
          searchArrayList.add("Germany");
          searchArrayList.add("Spain");
  
          AutoCompleteAdapter adapter = new AutoCompleteAdapter(this,
                  R.layout.list_item, R.id.textView1, searchArrayList);
  
          AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.searchAutoComplete);
          autoCompleteTextView.setDropDownWidth(getResources().getDisplayMetrics().widthPixels);
          autoCompleteTextView.setAdapter(adapter);
  </code></pre>
  
  <p><strong>Custom AutoCompleteAdapter class implementation using ArrayAdapter</strong></p>
  
  <p>AutoCompleteAdapter.java</p>
  
  <pre><code>public class AutoCompleteAdapter extends ArrayAdapter&lt;String&gt; implements
          Filterable {
  
      private ArrayList&lt;String&gt; fullList;
      private ArrayList&lt;String&gt; mOriginalValues;
      private ArrayFilter mFilter;
  
      public AutoCompleteAdapter(Context context, int resource,
                                 int textViewResourceId, ArrayList&lt;String&gt; fullList) {
  
          super(context, resource, textViewResourceId, fullList);
          this.fullList = fullList;
          mOriginalValues = new ArrayList&lt;String&gt;(fullList);
  
      }
  
      @Override
      public int getCount() {
          return fullList.size();
      }
  
      @Override
      public String getItem(int position) {
          return fullList.get(position);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          return super.getView(position, convertView, parent);
      }
  
      @Override
      public Filter getFilter() {
          if (mFilter == null) {
              mFilter = new ArrayFilter();
          }
          return mFilter;
      }
  
      private class ArrayFilter extends Filter {
          private Object lock;
  
          @Override
          protected FilterResults performFiltering(CharSequence prefix) {
              FilterResults results = new FilterResults();
  
              if (mOriginalValues == null) {
                  synchronized (lock) {
                      mOriginalValues = new ArrayList&lt;String&gt;(fullList);
                  }
              }
  
              if (prefix == null || prefix.length() == 0) {
                  synchronized (lock) {
                      ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;(
                              mOriginalValues);
                      results.values = list;
                      results.count = list.size();
                  }
              } else {
                  final String prefixString = prefix.toString().toLowerCase();
  
                  ArrayList&lt;String&gt; values = mOriginalValues;
                  int count = values.size();
  
                  ArrayList&lt;String&gt; newValues = new ArrayList&lt;String&gt;(count);
  
                  for (int i = 0; i &lt; count; i++) {
                      String item = values.get(i);
                      if (item.toLowerCase().contains(prefixString)) {
                          newValues.add(item);
                      }
  
                  }
  
                  results.values = newValues;
                  results.count = newValues.size();
              }
  
              return results;
          }
  
          @SuppressWarnings("unchecked")
          @Override
          protected void publishResults(CharSequence constraint,
                                        FilterResults results) {
  
              if (results.values != null) {
                  fullList = (ArrayList&lt;String&gt;) results.values;
              } else {
                  fullList = new ArrayList&lt;String&gt;();
              }
              if (results.count &gt; 0) {
                  notifyDataSetChanged();
              } else {
                  notifyDataSetInvalidated();
              }
          }
      }
  </code></pre>
  
  <p>I know that above implementation is not the right way to do it. But what I need to know whether is there any other way or library to accomplish it. I also see that in recent days many of the applications are using similar search bar, kindly please help me with the solutions since no where i can see the exact solutions for these requirement. </p>
  
  <p>In most of the blogs and websites there is only solutions <a href="http://developer.android.com/guide/topics/ui/actionbar.html" rel="nofollow noreferrer">like</a>. </p>
  
  <p>Sorry to say this too that most of the StackOverflow posts are also left un answered for the similar questions as follows:</p>
  
  <p><a href="https://stackoverflow.com/questions/23932157/implement-search-bar-like-in-play-store-app">Implement search bar like in play store app</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18847687/how-to-create-search-bar-look-like-google-play">How to create search bar look like google play</a> </p>
  
  <p>All your solutions and suggestions are welcome. Kindly please forgive me if my post is not clear and seems unrelevant. Expecting your answers. Thanks in advance</p>