Android Listview item UI change - android

I have a listview, each item in listview have a button.
I set a onClickListener to the button to play music.
Each time, only "ONE MUSIC" can be played!!!
But so far, I haven't implemented the play music part, I just handle the UI change first.
When I click the button,
1) The "play" image of the button will change to "stop".
2) If the music is already playing, it will stop the previous song(and change the UI of corresponding listview item image to "stop"), and then play the selected song(and change the UI of corresponding listview item image to "play).
Now I faced some problems and don't know how to fix it.
Q1) When one song is playing, and I scroll the listview up and down, the "stop" image will change back to "play", so the user don't know which item is playing.
Q2) This is the hardest problem!!
When one song is already playing, and user click another song, I don't know how to notify the previous listview item to change the UI from "song" to "play"(since the previous music will stop).

Related

android reach next and previous item of listview

I have a listView that filled by custom Adapter and listed some sounds from external storage.
when user click on each item of listView a custom alerDialog pop-up and it has play, next and previous buttons.
The problem is I have no idea how to reach information of next and previous sound in listView to play them in this alertDialog without closing it?(in other words I want to reach information of my listView from another class(alertDialog)) Thanks for help.

change appearance of related views depending on which view was clicked, without a big long switch statement

I have an app that has a lot of buttons, and when a button is clicked, it plays a corresponding sound depending on which button was clicked.
I'm doing this by using the name of the button that was clicked to get the internal android resource ID of the sound file with the same name, and playing that sound, all in one method, and eliminating the need to test which button was clicked with a big long switch statement.
Now I want to do something similar to change the appearance of related views (ie. not the button that was clicked but 2 other views related to which button was clicked, once again without the big long switch statement, the difference being that it is multiple views I want to change the appearance of, that aren't passed to the onClick listener.
Any ideas how to go about this?
Thanks

Concern about listview in android

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.
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
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.
You face 2 problems:
Hight light the row at selected song:
You can try set background at the selected song view to hight light it.
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

Schedule List View items

I have a list view and two buttons(play & pause) I want that to when a play button touched a list view's first item go on top of page for example for 6 seconds and next item after first item be on top for 3 seconds and ...
This means Successively items go to top of list view's page and when I touch pause button it stop working and when I touch play button again it continue working
What can I do?
Sorry For my poor English
Sorry
you can keep a track of the last visible item on the screen like a counter. On click of play button increase the value of counter by 1 and set smooth scroll to the counter value. Do this inside a Timer object pass a TimerTask to create a new timer object and schedule it to run over and over again. Hope this helps.
http://developer.android.com/reference/java/util/Timer.html
http://developer.android.com/reference/java/util/TimerTask.html

In listview changing background of button in rows on click of button in one row

I have a listview with play button to play songs in each row. When i click on play button its background changes to pause button. What i want is when I click on play button in one row, the button that has background set to pause image on previous click should automatically change to play image and only the button which I has clicked should have pause background.
On click of button in a row of listview how to change other rows buttons background?
Regards,
Naresh T
I'll give you the basic idea of how you could implement this. You need to have a custom Adapter which would store the View which is currently set to "playing" state. Let's say, it would be called mCurPlaying. After the user clicks another View, change the background of the mCurPlaying and replace it with the newly clicked View.
Should you have any problems with implementing this, please, drop a note and I'll give you some more hints in code.
Instead of writing on click for whole row set only onclick for a button in that row in getview method of adapter class it solved your problem.

Categories

Resources