-1

I'm having songs ArrayList like this

songs.add(new Songs("Rumour Has It","Adele", "Adele21", R.drawable.adele, 1991, R.drawable.adele21_cover));

songs.add(new Songs("Turning Tables","Adele", "Adele21", R.drawable.adele, 1991, R.drawable.adele21_cover));

songs.add(new Songs("dangerous","M Jackson", "Dangerous", R.drawable.jackson, 1992, R.drawable.dangerous_cover));

I want to get the index of ArrayList row which has the song "Turning Tables" which is now playing so I can play next or previous song

String songName = preferenceConfig.readSongName();
for(Songs s : MainActivity.songs){
    boolean resultOfComparison= songName.equals(s.getSong());
    if(resultOfComparison){
       //how to get the index of this row which contains this song
    }
 }
PHP User
  • 1,748
  • 2
  • 29
  • 58
  • check out this https://stackoverflow.com/questions/3431529/java-how-do-i-get-current-index-key-in-for-each-loop – Elias Fazel Apr 07 '19 at 00:17

1 Answers1

0
for(Songs s : MainActivity.songs) {
     boolean resultOfComparison= songName.equals(s.getSong());
     if(resultOfComparison){
        Toast.makeText(context, "Current index is: " + (songIndex), Toast.LENGTH_SHORT).show();
        }
     songIndex++;
}
PHP User
  • 1,748
  • 2
  • 29
  • 58