Android Data Binding Library vs Kotlin Android Extensions


I'm reading about how the MVVM architecture works and how to use Android Data Binding Library help.

In a very general way I understand that Android Data Binding creates a link between UI layer and the underlying data model that holds the information to display.

Kotlin Android Extensions are another Kotlin plugin that will allow you to recover views from Activities, Fragments and Views. The plugin will generate some extra code that will allow you to access views in the XML layout, just as if they were properties with the name of the id you used in the layout definition.

What is the difference between using Android Data Binding Library and Kotlin Android Extensions? Are they for different purposes? Do they complement each other, in what way?

Thank you for your answers.

Best Solution

Both, Kotlin Android Extensions and Android Data Binding Library help to eliminate the use of findViewById.

But there are also more things that these do, that can complement one another. To elaborate, with the Android Data Binding library, you can 'set' models in your xml files, which can then directly be leveraged to set values for the views in the layout. See how a <data> tag can be used with the data binding library.

Kotlin android extensions does not provide for this. At the same time, Kotlin android extensions provides for some amazing features like @parcelize annotation to make classes parcelable with almost no boilerplate code, etc.

To conclude, while they both eliminate the use of findViewById, they have their own features too which can complement one another well.