Today, you’ll learn how to link views with the code using view binding instead of legacy findViewById
or a heavyweight data-binding framework. In my previous articles, we covered the basics. In this article, we’ll cover Android components like dialogs and adapters.
For those who are new to view binding, it’s a lightweight library from the Jetpack family to link views with Android components. In the current Android environment, we have four solutions to link views with Android components:
findViewById
— This is the legacy solution that involves more manual work.If you’re interested in learning more about these four types, I recommend reading this article.
The idea behind ViewBinding
is to create a binding class for every layout that holds the references of the views in the layout. This reduces boilerplate code in your component (dialog and adapter), and we can access views by creating an instance to that class. If you’re new to view binding, read the following article to learn about how to add the library and use it in high-level Android components such as activities and fragments.
#kotlin #android #mobile