New In Android: View Binding. The Difference From DataBinding Library.

Anastasia Finogenova
ProAndroidDev
Published in
4 min readMay 16, 2019

--

No, they are not the same, even if the naming sounds really similar. ViewBindings were introduced at the What’s new in Android talk at Google IO/19. It is a new API and it has a similar concept as DataBinding so let’s figure out the difference and what we can leverage from it.

What is view binding?

The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically. You can read more here. To enable DataBinding you need to enable the property in Gradle file (starting AndroidX no need to import the library).

ViewBinding serves the same purpose, it is enabled by enabling the property in Gradle. No need to include additional imports.

Why using bindings and not findViewById?

So what difference does enabling ViewBinding/DataBinding make VS just calling findViewById?

  1. Elegance.

findViewById lacks elegance. It is not convenient initializing every view by id and declaring it as separate variables. It leads to a bunch of boilerplate code which clutters Fragment or Activity. ViewBinding/DataBinding can provide a nice way of directly calling views by id with just…

--

--