title: Implementing multi selection in Android RecyclerView
body: <p>I need some help with Multi/Single selection. Found what I was looking for <a href="https://stackoverflow.com/a/40551984/5482999">here</a>, because of its simplicity.
  I'm using a <code>GridLayoutManager</code> I have over 90 items in my adapter, a <code>CardView</code> with a <code>TextView</code> and an <code>ImageView</code>, while using the procedure described in <a href="https://stackoverflow.com/a/40551984/5482999">the post</a>. </p>
  
  <p>When I select one, or more than one item, as I scroll down, other items "seems" to be selected because the background replicates, but they are not selected.
  Tried placing the <code>setOnClickListener</code>, in <code>onBindViewHolder</code> and also in MyViewHolder class and in both of them I get the same behaviour. When scrolling down other items seems to be selected.
  Used <code>notifyItemChanged(position)</code> and <code>notifyDataSetChanged()</code> in the adapter, but the background does not change at all, although the <code>setSelected</code> works properly.
  Also I used <code>setHasFixedSize(true)</code> in the RecyclerView setup.</p>
  
  <p>In <code>onBindViewHolder</code></p>
  
  <pre><code>@Override
  public void onBindViewHolder(MyViewHolder myViewHolder, final int position) {
  
      PatternImages currentPattern = patternImages.get(position);
      myViewHolder.setData(currentPattern, position);
      myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              v.setSelected(!v.isSelected());
              if (v.isSelected()) {
                  v.setBackgroundColor(ContextCompat.getColor(context, R.color.colorPrimaryHighLight));
  
              } else {
                  v.setBackgroundColor(Color.WHITE);
  
              }
              notifyItemChanged(position);
          }
      });
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>public class PatternImages {
  
      private int imageId, imageName;
      private boolean isSelected;
  
      public PatternImages(int imageId, int imageName, boolean isSelected) {
  
          this.imageId = imageId;
          this.imageName = imageName;
          this.isSelected = isSelected;
      }
      public int getImageId() {
  
          return imageId;
      }
      public void setImageId(int imageId) {
  
          this.imageId = imageId;
      }
      public int getImageName() {
  
          return imageName;
      }
      public void setImageName(int imageName) {
  
          this.imageName = imageName;
      }
      public boolean isSelected() {
  
          return isSelected;
      }
      public void setSelected(boolean selected) {
  
          isSelected = selected;
      }
  </code></pre>
  
  <p>RecyclerView Setup</p>
  
  <pre><code> private void setUpPatternsRecyclerView() {
  
      RecyclerView recyclerPatternsView = (RecyclerView) findViewById(R.id.pattern_image_recycler_view);
      PatternImageAdapter adapter = new PatternImageAdapter(this, patternImages);
      recyclerPatternsView.setAdapter(adapter);
      ColumnQty columnQty = new ColumnQty(this, R.layout.item_image_pattern_cardview);
      GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), columnQty.calculateNoOfColumns());
      recyclerPatternsView.setHasFixedSize(true);
      recyclerPatternsView.setLayoutManager(gridLayoutManager);
      recyclerPatternsView.setItemAnimator(new DefaultItemAnimator());
      recyclerPatternsView.addItemDecoration(new GridSpacing(columnQty.calculateSpacing()));
  
  }
  </code></pre>
  
  <p>setData Method</p>
  
  <pre><code>public void setData(PatternImages currentPattern, int position) {
  
      this.position = position;
      patternName.setText(context.getString(currentPattern.getImageName()));
      patternName.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/ElMessiri-SemiBold.ttf"));
      patternImage.setBackgroundResource(currentPattern.getImageId());
      if (position == 0 || position == 1) {
          animationDrawable = (AnimationDrawable) patternImage.getBackground();
          animationDrawable.start();
      }
  
  
  }
  </code></pre>