title: Selected items in RecyclerView change on scrolling
body: <p>I have a RecyclerView with each element representing an event. I want to let the user select events by clicking it. Once selected, the event(s) and a report button will be colored:</p>
  
  <p>UI before performing a click: <a href="http://i.stack.imgur.com/bcTxa.png" rel="nofollow">click here</a>.</p>
  
  <p>UI After performing a click: <a href="http://i.stack.imgur.com/oIMc0.png" rel="nofollow">click here</a>.</p>
  
  <p>It's pretty simple and allegedly works; I set an <code>OnClickListener</code> for each <code>ViewHolder</code> which is responsible for coloring the item, and when fired it's triggering another event in the owning activity named <code>onOccurrenceSelected</code>, which is responsible for changing the button's state.</p>
  
  <p>However, when scrolling through the RecyclerView's items, other irrelevant items are colored like their <code>OnClickListener</code> was triggered (though it wasn't), and when scrolling back the selected event is colored as not selected. While this is happening, the only event that's supposed to color the items is not triggered.</p>
  
  <p>Any explanation for such behavior? Thanks!</p>
  
  <p><strong>EDIT: Here are some relevant code from the adapter:</strong></p>
  
  <pre><code>private List&lt;Occurrence&gt; mDataSet;
  private Activity activity;
  
  public &lt;OccurrencesActivity extends OnOccurrenceSelectedListener&gt; OccurrencesAdapter(OccurrencesActivity occurrencesActivity, List&lt;Occurrence&gt; occurrences) {
      this.activity = (android.app.Activity) occurrencesActivity;
      mDataSet = occurrences;
  }
  
  @Override
  public void onBindViewHolder(final ViewHolder holder, final int position) {
      Occurrence instance = mDataSet.get(position);
      ...
      setOnClickListener(holder, instance);
      }
  
  private void setOnClickListener(final ViewHolder holder, final Occurrence occurrence) {
      holder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if (!occurrence.isSelected()) {
                  holder.itemView.setBackgroundColor(App.getContext().getResources().getColor(R.color.turquoise));
                  holder.titleTextView.setTextColor(App.getContext().getResources().getColor(R.color.white));
                  holder.statusTextView.setTextColor(App.getContext().getResources().getColor(R.color.white));
                  holder.dateTextView.setTextColor(App.getContext().getResources().getColor(R.color.white));
                  holder.timeTextView.setTextColor(App.getContext().getResources().getColor(R.color.white));
              } else {
                  holder.itemView.setBackgroundColor(App.getContext().getResources().getColor(R.color.white));
                  holder.titleTextView.setTextColor(App.getContext().getResources().getColor(R.color.turquoise));
                  holder.statusTextView.setTextColor(App.getContext().getResources().getColor(R.color.grey));
                  holder.dateTextView.setTextColor(App.getContext().getResources().getColor(R.color.grey));
                  holder.timeTextView.setTextColor(App.getContext().getResources().getColor(R.color.grey));
              }
              occurrence.setSelected(!occurrence.isSelected());
  
              ((OnOccurrenceSelectedListener)activity).onOccurrenceSelected(mDataSet);
          }
      });
  }
  </code></pre>