Create a ViewModel (Pick Players)
View models as a concept aren’t an exclusively Android-focused idea; plenty of other languages/frameworks/platforms have the concept of a view model in one way or another. In a general sense, a view model holds UI-related data for a given view. This way, the UI can focus on what to display while the view model handles how you get that data.
With Jetpack, ViewModel is a specific class we can use to handle UI data for view components, in our case the Fragment classes. A ViewModel may also contain LiveData, which will automatically send updates to a UI controller whenever the data changes. Since ViewModel classes are life-cycle aware, they only send LiveData over when a given Fragment (or Activity) is currently ...
Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.