title: Loading next item after clicking next button in recyclerView
body: <p>I have an activity called <code>ArtistActivity</code>, which contains a RecyclerView which loads song data from Firebase and shows it in the Artist Activity. I have an adapter class and a View Holder class for my <code>ArtistActivity</code> RecyclerView. When I click the item in my RecyclerView it sends <code>songUrl</code> , <code>songName</code>, <code>songArtist</code> to another activity called <code>SongPlayingActivity</code> which takes <code>songUrl</code> and plays the song.</p>
  
  <p>My main question is I have the next button in my <code>SongPlayingActivity</code> and I want to load the next item after the user clicks the next button. Like if the user clicks the Next Button then it stops the previous playing song and loads the next song from songList. Much like how it works on Spotify.</p>
  
  <p>I hope you understand my question and if you have any answers regarding this then please reply.</p>
  
  <p>Here is my code: -</p>
  
  <p><strong>ArtistActivity:</strong></p>
  
  <pre><code>public class ArtistActivity extends AppCompatActivity {
      private RecyclerView mRecyclerView;
      private ValueEventListener eventListener;
      private DatabaseReference mDataRef, artist_ref;
  
      private List&lt;PanelList&gt; mList;
      private PanelAdapter panelAdapter;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.artist1layout);
  
          mRecyclerView = findViewById(R.id.artist_song_recyclerview);
          mDataRef = FirebaseDatabase.getInstance().getReference("ArtistView").child(getIntent().getStringExtra("Artist"))
                  .child("Songs");
  
  
          mRecyclerView.setHasFixedSize(true);
  
          mDataRef.keepSynced(true);
  
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          mList = new ArrayList&lt;&gt;();
  
          panelAdapter = new PanelAdapter(ArtistActivity.this, mList);
  
          mRecyclerView.setAdapter(panelAdapter);
  
          eventListener = mDataRef.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  mList.clear();
                  for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                      PanelList list = postSnapshot.getValue(PanelList.class);
                      mList.add(list);
  
  
                  }
  
                  panelAdapter.notifyDataSetChanged();
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
              }
          });
      }
  }
  </code></pre>
  
  <p><strong>ViewHolder/Adapter class:</strong></p>
  
  <pre><code>public class PanelAdapter extends RecyclerView.Adapter&lt;PanelAdapter.PanelViewHolder&gt; {
  
  
      private Context mContext;
      private List&lt;PanelList&gt; mUploads;
  
  
      public PanelAdapter(Context context, List&lt;PanelList&gt; panelList) {
  
          mContext = context;
          mUploads = panelList;
  
      }
  
      @NonNull
      @Override
      public PanelViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(mContext).inflate(R.layout.artist_recycler_layout, parent, false);
          return new PanelViewHolder(v);
  
         // Toast.makeText(mContext, "" + ge, Toast.LENGTH_SHORT).show();
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull PanelViewHolder holder, int position) {
  
          PanelList panelList = mUploads.get(position);
  
  
          holder.textViewName.setText(panelList.getSongName());
  
          Glide.with(mContext)
                  .load(panelList.getSongImageUri())
                  .centerCrop()
                  .into(holder.circleImageView);
          holder.thisLayout.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  String url = panelList.getSongUrl();
  
                  Intent playSongActivity = new Intent(mContext, D.class);
                  playSongActivity.putExtra("SongUrl", panelList.getSongUrl());
  
  
                  mContext.startActivity(playSongActivity);
              }
          });
  
    }
  
      @Override
      public int getItemCount() {
          return mUploads.size();
      }
  
      public class PanelViewHolder extends RecyclerView.ViewHolder {
  
          private LinearLayout thisLayout;
  
  
  
          public PanelViewHolder(@NonNull View itemView) {
              super(itemView);
  
              thisLayout = itemView.findViewById(R.id.artist_linear);
  
  
  
          }
  
      }
  }
  </code></pre>
  
  <p>My D class: -</p>
  
  <pre><code>public class D extends AppCompatActivity {
  
      public static SeekBar mSeekbar;
      public static ImageView Play_Icon_D;
  
      private Button next_button;
      //  private Button popup_button;
  
      private TextView Song_D, Artist_D;
  
      private Integer currentIndex;
  
      private List&lt;PanelList&gt; panelList;
  
      private Bundle bundle;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_song_playing);
  
          mSeekbar = findViewById(R.id.seekbar);
  
          Play_Icon_D = findViewById(R.id.play_icon_D_class);
  
          Song_D = findViewById(R.id.song_info_song_D);
  
          Artist_D = findViewById(R.id.song_info_artist_D);
  
          next_button = findViewById(R.id.D_next_button);
  
          bundle = getIntent().getExtras();
  
          panelList = bundle.getParcelableArrayList("SongUrls");
  
          currentIndex = bundle.getInt("currentPlayingIndex");
  
  
          playSong();
  
  
          next_button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  String newUrl = panelList.get(currentIndex).getSongName();
                  currentIndex = currentIndex + 1;
  
  //                Toast.makeText(D.this, newUrl, Toast.LENGTH_SHORT).show();
  
                  FirebaseStorage storage = FirebaseStorage.getInstance();
  
                  StorageReference reference = storage.getReferenceFromUrl(panelList.get(currentIndex).getSongUrl());
  
                  reference.getDownloadUrl().addOnFailureListener(uri -&gt; C.getInstance().play(uri.toString()));
  
  
              }
          });
  
      }
  
      private void playSong() {
          FirebaseStorage storage = FirebaseStorage.getInstance();
          StorageReference reference = storage.getReferenceFromUrl(panelList.get(currentIndex).getSongUrl());
  
          reference.getDownloadUrl().addOnFailureListener(uri -&gt; C.getInstance().play(uri.toString()));
  
      }
  
  
  }
  </code></pre>