VOOZH about

URL: https://www.geeksforgeeks.org/android/data-binding-in-android-with-example/

⇱ Data Binding in Android with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Data Binding in Android with Example

Last Updated : 23 Jul, 2025

In Android, 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.

Step by Step Implementation:

Step 1: Create a New Project

If you don’t know how to create a new project in Android Studio then you can refer to How to Create/Start a New Project in Android Studio? 

Step 2: Enable Data Binding

Navigate to Gradle Scripts > build.gradle.kts(module level).

πŸ‘ gradle_module_java


Add the below code snippet to the build.gradle.kts (module level) file under the android{} scope to activate Data Binding in the application:

buildFeatures {
dataBinding = true
}

Step 3: Create a model class

Navigate app > kotlin+java > {package-name}. Right click on it and go to New > Kotlin Class/File or Java Class. Set the name Company for the file. Add the following code to the file.


Step 4: Working on activity_main.xml

Navigate to the app > res > layout > activity_main.xml and add the below code to that file.

πŸ‘ activity_main_Java


activity_main.xml:

Step 5: Working on Main Activity file

Navigate to the MainActivity.java/MainActivity.kt file and use the following code in it. Comments are added to the code to have a better understanding.

Output:

πŸ‘ databinding
Comment

Explore