title: Android: fix RecyclerView filtering on spinner selection?
body: <p>I have a RecyclerView list of a number of CardViews.  I would like to filter the list when the user selects an item from a spinner dropdown dialog.  The item selection from the spinner narrows down the list to a smaller set of the original CardViews. My problem is that the list is being filtered somehow when I add a new CardView to the list which occurs before the user ever makes any item selection with the spinner.  So no new CardView shows in the Recyclerview list, it is just a blank RecyclerView list.  I only want the CardViews to be filtered when the user makes an item selection from the spinner, not every time a CardView is added to the RecyclerView list.  What am I missing here?</p>
  
  <pre><code>MainActivity
  public class MainActivity extends AppCompatActivity {
  
      private RecyclerView sRecyclerView;    
      private MyRecylerAdapter adapter;
      private List&lt;ListItem&gt; allList;
      ...
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      // For filtering by the CardView type.
      final Spinner spinner2;        
      spinner2 = (Spinner) findViewById(R.id.skycard_filter);
      String[] spinnerItems2 = getResources().getStringArray(R.array.skycard_filters);        
      final CustomAdapter&lt;String&gt; adapter2 = new CustomAdapter&lt;&gt;
              (this,android.R.layout.simple_spinner_item, spinnerItems2);
      adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner2.setAdapter(adapter2);
      spinner2.setPrompt("Filter CardView type");
  
      spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view,
              int position, long id) {
  
              String type = spinnerItems2[position];
              final ArrayList&lt;ListItem&gt; filteredModelList2 = adapter.filter2(adapter.listItems,type);
              adapter.setFilter(filteredModelList2);
          }
          @Override
          public void onNothingSelected (AdapterView &lt; ? &gt; adapterView){
              // auto-generated
          }
      });
  }
  
  Adapter
  public class MyRecylerAdapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
      public List&lt;ListItem&gt; listItems;
      ...
      // Do Search filtering from MainActivity.
      public ArrayList&lt;ListItem&gt; filter2(List&lt;ListItem&gt; models, String filterType) {
  
          final ArrayList&lt;ListItem&gt; filteredModelList2 = new ArrayList&lt;&gt;();
          for (ListItem model:models) {
              final String cardTypeTest = model.getType();
  
              if (cardTypeTest.equals(filterType)) {
                  filteredModelList2.add(model);
              }
          }
          return filteredModelList2;
      }
  
      public void setFilter2(ArrayList&lt;ListItem&gt; listItem) {
          listItems = new ArrayList&lt;&gt;();
          listItems.addAll(listItem);
          notifyDataSetChanged();
      }
  }
  </code></pre>