Deprecated: class-phpmailer.php is deprecated since version 5.5.0! Use wp-includes/PHPMailer/PHPMailer.php instead. The PHPMailer class has been moved to wp-includes/PHPMailer subdirectory and now uses the PHPMailer\PHPMailer namespace. in /opt/bitnami/apps/wordpress/htdocs/wp-includes/functions.php on line 4967
Android data binding library using kotlin with example
Notice: Trying to get property 'display_name' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 152

Notice: Trying to get property 'user_email' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 230

Notice: Trying to get property 'display_name' of non-object in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-person.php on line 236
Home Android Android Data Binding Using Kotlin

Android Data Binding Using Kotlin

Android Data Binding Using Kotlin


Android Data binding is one of the hot topic among Android developers ever since its first launch in Mid 2015, helping to build the apps faster.

This Article explains about the same, Data binding Library concept and how to use it in android using Kotlin. Data Binding not only supports in eliminating boilerplate code but also helps in faster development times and faster execution times.


  • It eliminates boilerplate code (like findViewById)
  • It provides a stronger readability, it would be easy to learn about it.
  • Provides support to separate UI logic and business logic.

Similar Links: How to Read a File using Kotlin

Let’s see how to implement data binding in our application.

Configuring Android Data Binding:

To enable the usage of data binding in your app, first edit your application’s build.gradle file and add the following code snippet.

Data Binding Layout File:

Generally, in default layout files we have ViewGroup(E.g:LinearLayout, RelativeLayout) as parent tag. But, in this case to support data binding techniques, we must have <layout> tag as root tag. For a MainActivity class, a activity_main.xml layout would be like this:

Actual view (here it is Constraint layout) is defined within layout tag to support data binding techniques.The layout tag is a tag which indicates build system that, this file should be processed for data binding. Any layout file is without that tag , will not support data binding.

Data Binding Activity:

After this, binding class will be auto generated based on the name of layout file by default.To associate it in your class, invoke setContentView() using DataBindingUtil like this:

That’s it, we are done. Run the project and check output.

References: Data Binding Library implementation



0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x