title: How to change an item that isn't the one I clicked in a RecycleView?
body: <p><strong>Summary</strong></p>
  
  <p>I have a CardView in a RecycleView with a button to play or stop a song and only one song should be played at a time. So when I click one of this buttons, all the others should have a "play" icon while the clicked one should have a "stop" icon. Basically, I need to change the image of an item that I didn't click.</p>
  
  <p><strong>The problem</strong></p>
  
  <p>The project compiles, the songs don't overlap when multiples are played simultaneously and when I click an icon it changes to the other icon, but if I click another item, the previous one clicked don't change back and stays the same. </p>
  
  <p><strong>Attempt</strong></p>
  
  <p>So, I've tried to iterate over all the elements of the RecycleView, to change them back to a default icon and later just change the clicked icon, but I couldn't really access the other items that I didn't click. I've tried to reference the previous item with a global variable, but, again, I couldn't really handle this previous item.</p>
  
  <p><strong>The AudioGridActivity code:</strong></p>
  
  <pre><code>public class AudioGridActivity1 extends AppCompatActivity {
  private RecyclerView recyclerView2;
  private MyAdapter2 adapter2;
  private RecyclerView.LayoutManager layoutManager;
  
  private ArrayList&lt;CardAudioGrid&gt; mList;
  
  private MediaPlayer song;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_audio_grid1);
      createList();
      buildRecyclerView();
  
      final ImageView mediaPlayer = (ImageView) findViewById(R.id.mediaPlayerId); // this is the play/stop "button"
  
      adapter2.setOnItemClickListener(new MyAdapter2.OnItemClickListener() {
          @Override
          public void onPlayClick(int position) {
              switch(position){
                  case 0:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
                  case 1:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
                  case 2:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
                  case 3:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
                  case 4:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
                  case 5:
                      pauseTheme();
                      song = MediaPlayer.create(AudioGridActivity1.this, R.raw.gato);
                      playTheme();
                      break;
  
  
              }
  
          }
      });
  
  }
  
  public void createList(){
      mList = new ArrayList&lt;&gt;();
      mList.add(new CardAudioGrid(R.drawable.mediaplay2, R.color.colorAccent, ""));
      ...
      mList.add(new CardAudioGrid(R.drawable.mediaplay2, R.color.colorPrimary, ""));
  }
  
  public void buildRecyclerView() {
      recyclerView2 = findViewById(R.id.recyclerViewId2);
      recyclerView2.setHasFixedSize(true);
      layoutManager = new GridLayoutManager(this, 2);
      recyclerView2.setLayoutManager(layoutManager);
      adapter2 = new MyAdapter2(this, mList);
      recyclerView2.setAdapter(adapter2);
  }
  public void playTheme(){
      if(song!=null) song.start();
  }
  public void pauseTheme(){
      if(song!=null &amp;&amp; song.isPlaying()) song.release();
  }
  ...}
  </code></pre>
  
  <p><strong>The Adapter code:</strong></p>
  
  <pre><code>public class MyAdapter2 extends RecyclerView.Adapter&lt;MyAdapter2.MyViewHolder&gt;{
  private Context mContext;
  private List&lt;CardAudioGrid&gt; mList;
  private OnItemClickListener mListener;
  
  public interface OnItemClickListener{
      void onPlayClick (int position);
  }
  public void setOnItemClickListener(OnItemClickListener listener){
      mListener = listener;
  }
  
  public MyAdapter2(Context mContext, List&lt;CardAudioGrid&gt; mList) {
      this.mContext = mContext;
      this.mList = mList;
  }
  
  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      LayoutInflater inflater = LayoutInflater.from(mContext);
      View view = inflater.inflate(R.layout.audiocard, viewGroup, false);
      return new MyViewHolder(view, mListener);
  }
  @Override
  public void onBindViewHolder(MyViewHolder holder, int position) {
      holder.audioCardBackground.setImageResource(mList.get(position).getCardBackground());
      ...
      holder.mediaPlayer.setImageResource(mList.get(position).getPlayButton());
  }
  @Override
  public int getItemCount() {
      return mList.size();
  }
  
  public class MyViewHolder extends RecyclerView.ViewHolder{
      ImageView mediaPlayer, audioCardBackground;
  
      public MyViewHolder(View itemView, final OnItemClickListener listener) {
          super(itemView);
  
          mediaPlayer = (ImageView) itemView.findViewById(R.id.mediaPlayerId);
          audioCardBackground = (ImageView) itemView.findViewById(R.id.cardbackgroundId);
          mediaPlayer.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(listener!=null){
                      int position = getAdapterPosition();
                      if (position != RecyclerView.NO_POSITION){
                          listener.onPlayClick(position);
                          mediaPlayer.setImageResource(R.drawable.mediapause2);
                      }else{
  
                      }
                  }
              }
          });
      }
  
  }
  }
  </code></pre>
  
  <p>How should I solve this problem?</p>
  
  <p>I am currently learning how to manage the android properly, so I would really appreciate if you explain the steps' solutions.</p>