0

I am developing music application for android. I am done with most of the parts but i need help for Listview .

Suppose that user selects a song from list in Main and then it goes to new activity to play that song. In new activity user has option for next button to play next song . Now when user clicks next button 10 times and consider current playing song is XYZ. when user come back to main activity i want to highlight that song XYZ from list and display it on top of screen from list.

Please advise how to show that song on top in listview. I am able to find the position of XYZ from list but don't know how to highlight it and display it on top in current list.

Hope i made myself clear about this whole. thanks in advance.

Amar
  • 420
  • 3
  • 14
parmar131
  • 3
  • 1
  • If you have the index of the current song, you can send that index back to the main activity and from there set a scroll offset of `index * listItemHeight` or something like that. – Raymond Oct 22 '15 at 15:29
  • http://stackoverflow.com/questions/7561353/programmatically-scroll-to-a-specific-position-in-an-android-listview – kris larson Oct 22 '15 at 15:32
  • thanks Raymond, thats what i was looking for. i will try it – parmar131 Oct 22 '15 at 15:35

3 Answers3

0

Have you considered adding a header and then is there is a selected song you add that song as the header if there is no selected song you set header visibility to GONE.

Val Okafor
  • 3,371
  • 13
  • 47
  • 72
0

i would suggest that when you enter the new activity of playing the song you save the position of the song in your case XYZ.

so now when you go back use that value and pass it to your intent. and in your main activity u get the value so set the postion of the listview.

lv.smoothScrollToPosition(position);

Hope this helps you

Parth Anjaria
  • 3,961
  • 3
  • 30
  • 62
0

You face 2 problems:

  1. Hight light the row at selected song: You can try set background at the selected song view to hight light it.
  2. Show the playing song at the top of the ListView. About show to top ListView. You can use ListView.addHeader... to add playing song view to top view.

Hope you solve it

BaDo
  • 540
  • 8
  • 19