MVVM pattern definition
📌 MVVM stands for Model, View, ViewModel.
View
- It represents the UI of the application devoid of any Application Logic.
- It observes the
ViewModel
.
ViewModel
- It acts as a link between the
Model
and theView
. - It’s responsible for transforming the data from the
Model
. - It provides data streams to the
View
. - It also uses hooks or callbacks to update the
View
. - It’ll ask for the data from the
Model
.
Model
- This holds the data of the application.
- It cannot directly talk to the
View
. - It’s recommended to expose the data to the
ViewModel
through Observables
Android implementation components
📢 The following components are required to implement the sample app with Android and Kotlin. We will have two implementations: Simple MVVM with a text view and Simple MVVM with Recycle View.
View Binding
- View binding is a feature that allows you to more easily write code that interacts with views. Once view binding is enabled in a module, it generates a binding class for each XML layout file present in that module.
- An instance of a binding class contains direct references to all views that have an ID in the corresponding layout.
📌 In most cases, view binding replaces findViewById
.
View Binding | Android Developers
View binding is a feature that allows you to more easily write code that
interacts with views. Once view binding is enabled in a module, it generates a
binding class for each XML layout file present in that module. An instance of
a binding class contains direct references to all views that have an I…
interacts with views. Once view binding is enabled in a module, it generates a
binding class for each XML layout file present in that module. An instance of
a binding class contains direct references to all views that have an I…
ViewModel
- The
ViewModel
class is designed to store and manage UI-related data in a lifecycle conscious way. - The
ViewModel
class allows data to survive configuration changes such as screen rotations.
ViewModel overview | Android Developers
ViewModel lets you manage your UI's data in a lifecycle-aware fashion.
Lifecycle
- Lifecycle-aware components perform actions in response to a change in the lifecycle status of another component, such as activities and fragments. These components help you produce better-organized, and often lighter-weight code, that is easier to maintain.
Lifecycle | Android Developers
Lifecycle-aware components perform
actions in response to a change in the lifecycle status of another component,
such as activities and fragments. These components help you produce
better-organized, and often lighter-weight code, that is easier to maintain.
actions in response to a change in the lifecycle status of another component,
such as activities and fragments. These components help you produce
better-organized, and often lighter-weight code, that is easier to maintain.
LiveData
LiveData
is an observable data holder class.- Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.
- This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.
Recycler View
- RecyclerView makes it easy to efficiently display large sets of data.
- You supply the data and define how each item looks, and the RecyclerView library dynamically creates the elements when they’re needed.
Implementing your adapter and view holder
- Once you’ve determined your layout, you need to implement your
Adapter
andViewHolder
. - These two classes work together to define how your data is displayed.
- The
ViewHolder
is a wrapper around aView
that contains the layout for an individual item in the list. - The
Adapter
createsViewHolder
objects as needed, and also sets the data for those views. The process of associating views to their data is called binding.
Create dynamic lists with RecyclerView | Android Developers
RecyclerView makes it easy to efficiently display large sets of data. You supply
the data and define how each item looks, and the RecyclerView library
dynamically creates the elements when they’re needed.
the data and define how each item looks, and the RecyclerView library
dynamically creates the elements when they’re needed.
MaterialCardView
- This class supplies Material styles for the card in the constructor.
- The widget will display the correct default Material styles without the use of a style flag.
Github Repositories
TaskApp MVVM
GitHub – una-eif411-progra-mobile-master/frontend-taskapp-android at mvvm
Front End Android for TaskApp. Contribute to una-eif411-progra-mobile-master/frontend-taskapp-android development by creating an account on GitHub.