简体   繁体   中英

android update view upon event in singleton class

I am new to android development and am actually not sure about what exact term to be searching for this scenario. I have a singleton class which does some music play back stuff and I have 3 other list views in tabs which contain music tracks. Depending upon which track is playing in the singleton, I want that row in one or more of the list views to change backgroundColor to yellow and other ones to go white. How should I perform something like this?

I don't want to refresh/reload the entire list every time the track changes.

Should I be iterating through every single row to check against the singleton if it's the one playing? That could be resource consuming if a lot of rows exist. Or a better way? can some xml+java magic be used? What's the best way to perform this sort of thing in other languages like iOS?

Call <ListAdapter>.notifyDataSetChanged(); to notify the ListView that it should be refreshed, where is the adapter instance that was passed to the ListView . This will not iterate through every item in the list, but only the currently visible ones.

With the proper recycling of inflated view and the use of ViewHolder pattern , the overhead for updating a list can be kept to a minimum.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM