Relative Content

Tag Archive for androidandroid-recyclerviewarchitecture

Update items in a recycler view in a regular interval

I am trying to develop an app in android that shows me the current value of some stocks. I do this using a RecyclerView with an Adapter that binds this RecyclerView to a list of stocks from the database. The current value however is not stored in the database, but rather polled from an API. I do this by having a background thread in the Adapter that updates the stocks in a regular interval. The stocks in turn have an event that notifies the ViewHolder associated with the stock when the value of a stock item has changed. This works, but is messy because I am now mixing a database model with ui properties. And my approch with a background thread in the Adapter is probably not the right one either. I know that there is a ViewModel pattern in Android. But this does not seem to fit my situation because I would need a view model for each item in the RecyclerView rather than just one ViewModel instance for the entire application.