title: How to properly highlight selected item on RecyclerView?
body: <p>I am trying to use a <code>RecyclerView</code> as a horizontal <code>ListView</code>. I am trying to figure out how to highlight the selected item. When I click on one of the items, it gets selected and it is highlighted properly but when I click on another one, the second one gets highlighted with the older one. </p>
  
  <p>Here is my onClick function:</p>
  
  <pre><code>@Override
  public void onClick(View view) {
  
      if(selectedListItem!=null){
          Log.d(TAG, "selectedListItem " + getPosition() + " " + item);
          selectedListItem.setBackgroundColor(Color.RED);
      }
      Log.d(TAG, "onClick " + getPosition() + " " + item);
      viewHolderListener.onIndexChanged(getPosition());
      selectedPosition = getPosition();
      view.setBackgroundColor(Color.CYAN); 
      selectedListItem = view;
  }
  </code></pre>
  
  <p>Here is the <code>onBindViewHolder</code>:</p>
  
  <pre><code>@Override
  public void onBindViewHolder(ViewHolder viewHolder, int position) {   
      viewHolder.setItem(fruitsData[position]);
      if(selectedPosition == position)
          viewHolder.itemView.setBackgroundColor(Color.CYAN);    
      else
          viewHolder.itemView.setBackgroundColor(Color.RED);
  
  }
  </code></pre>