androidcoding.in
Published in

androidcoding.in

Data binding for android beginners.

Data binding is a way to bind the UI components like TextView,EditText….. to your code avoiding boiler plate code for initializing every view.

Data binding is a part of JetPack components, allowing a user to make a faster way to program.

Photo by JJ Ying on Unsplash

Enabling data binding:

Declaring in layout :

There is a mechanism to be implemented to get data binding, now include your layout file inside the

Let’s see a complete instruction

Now the crucial step is to generate a Activity Binding class, is automatically generated if you follow the steps this class is important to deal with data bindings

In your MainActivity class file we need to make use of this file and handle our databinding’s available in that particular layout file.

Generate a User model class for accessing the UI objects

Now initialize the class in MainActivity

Update the details into the Model class

then setData to UI components

Advantages

  1. Easy to implement and use as well.
  2. Faster than implementing findViewById pattern.
  3. Reduces boilerplate code.
  4. Readability of code is improved.
  5. Helpful in testing scenarios.
  6. A powerful way to deal with UI components.

For more detailed info visit

http://www.androidcoding.in/2020/02/23/android-data-binding-library-java-jet-pack/

--

--

Learn android from novice level by providing latest tutorials in a simple way.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store