I am working on an Android app using Java, and I have a RecyclerView
displaying a list of songs. When a song is selected, it starts playing, and the app navigates to a player Activity
. After returning to the original fragment with the song list, I want to highlight the currently playing song and display a playing animation (e.g., a GIF) next to it. Additionally, if another song is selected and starts playing, only the newly selected song should be highlighted, and the previous one should return to its default state.
Here is what I have done so far
I store the currently playing song’s details in a SessionManager
.
In my adapter’s onBindViewHolder
method, I check if the song is the currently playing one and update the UI accordingly.
In the fragment’s onResume
method, I call notifyDataSetChanged()
on the adapter to refresh the UI.
I am expecting if i change the songs anywhere in the app like from notification or miniplayer the
in that fragment song highlight is also change for current time.
HaxOfficial is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.