I am creating a music player. I want to play a selected song from ListView. But when i click on the specific item(song) in listview. I am not getting the item(song) i clicked in second class. The player always selects first song from list and plays the first song. I think that there is problem in code. Please check and correct. Thanks
Tab1(Sending Class)
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
int songIndex = position;
// Starting new intent
Intent in = new Intent(getActivity(), NowPlaying.class);
// Sending songIndex to PlayerActivity
in.putExtra("songIndex", songIndex);
getActivity().setResult(100, in);
// Closing PlayListView
getActivity().finish();
startActivity(in);
}
NowPlaying(Receiving Class)
/**
* Receiving song index from playlist view
* and play the song
*/
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {
currentSongIndex = data.getExtras().getInt("songIndex");
// play selected song
playSong(currentSongIndex);
}
}