title: AutoCompleteTextView with Custom Adapter filtering not working
body: <p>I have a <code>autocomplete text view</code> in my android project which is working fine but it only works if first value is entered in it. So for making it more customizable, I have added the below class</p>
  
  <pre><code>public class CustomArrayAdapterWIthFilter extends ArrayAdapter&lt;String&gt; implements Filterable {
  List&lt;String&gt; items = null;
  List&lt;String&gt; originalItems = null;
  private MyFilters myFilters = null;
  Context mContext;
  
  public CustomArrayAdapterWIthFilter(@NonNull Context context, @LayoutRes int resource, @NonNull List&lt;String&gt; objects) {
      super(context, resource, objects);
      this.items = new ArrayList&lt;&gt;();
      items.addAll(objects);
      this.originalItems = new ArrayList&lt;&gt;();
      this.originalItems.addAll(objects);
      mContext = context;
  }
  
  @Override
  public int getCount() {
      return items.size();
  }
  
  @Nullable
  @Override
  public String getItem(int position) {
      return items.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public void notifyDataSetChanged() {
      super.notifyDataSetChanged();
  }
  
  @NonNull
  @Override
  public Filter getFilter() {
      if (myFilters == null) {
          myFilters = new MyFilters();
      }
      return myFilters;
  }
  
  class MyFilters extends Filter {
  
      @Override
      protected FilterResults performFiltering(CharSequence constraint) {
          FilterResults result = new FilterResults();
  
          if (constraint != null &amp;&amp; constraint.toString().length() &gt; 0) {
              ArrayList&lt;String&gt; filteredItems = new ArrayList&lt;String&gt;();
  
              for (int i = 0, l = originalItems.size(); i &lt; l; i++) {
                  String item = originalItems.get(i);
                  if (item.toString().toLowerCase().contains(constraint))
                      filteredItems.add(item);
              }
              result.count = filteredItems.size();
              result.values = filteredItems;
          } else {
              synchronized (this) {
                  result.values = originalItems;
                  result.count = originalItems.size();
              }
          }
          return result;
      }
  
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
          items = (ArrayList&lt;String&gt;) results.values;
          notifyDataSetChanged();
          clear();
          for (int i = 0, l = items.size(); i &lt; l; i++)
              add(items.get(i));
          notifyDataSetInvalidated();
      }
  }
  
  public void addItems(List&lt;String&gt; items) {
      this.items = items;
      notifyDataSetChanged();
  }
  </code></pre>
  
  <p>In my fragment I have done the following</p>
  
  <pre><code>CustomArrayAdapterWIthFilter meterSrNumAdapter;
   if (meterSrNumAdapter.getCount() == 0) {
              meterSrArrayList = new MeterManager(getActivity()).getRefNoByStatus(Constants.SR_NO_UN_USED);
              meterSrArrayList.add(installationDetails.getMsn());
              meterSrNumAdapter.addItems(meterSrArrayList);
          }
   if (meterSrNumAdapter.getCount() == 0) {
              meterSrArrayList = new MeterManager(getActivity()).getRefNoByStatus(Constants.SR_NO_UN_USED);
              meterSrNumAdapter.addItems(meterSrArrayList);
          }
  
  meterSrArrayList = new ArrayList&lt;String&gt;();
      meterSrNumAdapter = new CustomArrayAdapterWIthFilter(getActivity(), R.layout.custom_spinner_layout, meterSrArrayList);
      smartMsnSpinner.setAdapter(meterSrNumAdapter);
      smartMsnSpinner.setSingleLine(true);
      smartMsnSpinner.setThreshold(1);
  
      smartMsnSpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
             selectedMeterNo = adapterView.getItemAtPosition(i).toString();
              Log.d("testtt", adapterView.getItemAtPosition(i).toString());
          }
  
  
      });
  </code></pre>
  
  <p>In above code <code>smartMsnSpinner</code> is my autocomplete text view</p>
  
  <p>When I run my app the autocomplete doesn't works. I have tried some other adapters which are placed over the internet. But still the result is same. I am trying for this custom adapter because in my another app it's working perfect and in this code I am doing the same.</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>After the suggestion I have changed the custom adapter code while considering the other part of the code is same as added above</p>
  
  <pre><code>List&lt;String&gt; suggestionItems = null;
  
  //In constructor
  this.items = new ArrayList&lt;&gt;(objects);
  
  this.originalItems = new ArrayList&lt;&gt;(objects);
  
  mContext = context;
  
  class MyFilters extends Filter {
  
      @Override
      protected FilterResults performFiltering(CharSequence constraint) {
  
          if(constraint !=null)
          {
              suggestionItems.clear();
  
              for(int i=0, i1 = originalItems.size(); i &lt;i1; i++)
              {
                  String item = originalItems.get(i);
                  if(item.toString().toLowerCase().contains(constraint))
                      suggestionItems.add(item);
              }
              FilterResults filterResults = new FilterResults();
              filterResults.values = suggestionItems;
              filterResults.count = suggestionItems.size();
              return filterResults;
          }
          else
          {
              return new FilterResults();
          }
  
      }
  
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
           if(results !=null &amp;&amp; results.count &gt; 0)
           {
               items.clear();
               items = (ArrayList&lt;String&gt;)results.values;
               notifyDataSetChanged();
           }
           else
           {
               items.addAll(originalItems);
           }
      }
  }
  </code></pre>
  
  <p>Any help would be highly appreciated.</p>