Data Binding in Android with Example Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 8 Likes Like Report 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 ProjectIf 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 BindingNavigate to Gradle Scripts > build.gradle.kts(module level). 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 classNavigate 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. Company.java package org.geeksforgeeks.demo; public class Company { private String name; private String website; public Company(String name, String website) { this.name = name; this.website = website; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getWebsite() { return website; } public void setWebsite(String website) { this.website = website; } } Company.kt package org.geeksforgeeks.demo data class Company ( val name: String, val website: String ) Step 4: Working on activity_main.xmlNavigate to the app > res > layout > activity_main.xml and add the below code to that file. activity_main.xml: activity_main.xml <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <data> <variable name="company" type="org.geeksforgeeks.demo.Company" /> </data> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:text="@{company.name}" android:textSize="24sp" app:layout_constraintBottom_toTopOf="@+id/website" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_chainStyle="packed" /> <TextView android:id="@+id/website" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{company.website}" android:textSize="24sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/name" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout> Step 5: Working on Main Activity fileNavigate 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. MainActivity.java package org.geeksforgeeks.demo; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import org.geeksforgeeks.demo.databinding.ActivityMainBinding; public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setting up Data Binding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); // Creating Company object and binding it to the layout Company company = new Company("GeeksforGeeks", "www.geeksforgeeks.org"); binding.setCompany(company); } } MainActivity.kt package org.geeksforgeeks.demo import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import org.geeksforgeeks.demo.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_main) val company = Company("GeeksforGeeks", "www.geeksforgeeks.org") binding.company = company } } Output: Data Binding in Android with Example Comment J jangirkaran17 Follow 8 Improve J jangirkaran17 Follow 8 Improve Article Tags : Android Geeks-Premier-League-2022 Kotlin Android Java-Android Explore Android Tutorial 10 min read BasicsIntroduction to Android Development 5 min read History of Android 15+ min read Best Way to Become Android Developer â A Complete Roadmap 7 min read Android Development Prerequisites [2025] - Things to Learn Before Android Development 8 min read Android App Development Fundamentals for Beginners 6 min read Android Architecture 5 min read Android System Architecture 3 min read Android Boot Process 4 min read Difference between Java and Kotlin in Android with Examples 3 min read Interesting Facts About Android 3 min read Software Setup and ConfigurationDownload and Instal JDK on Windows, Mac and Linux 7 min read Guide to Install and Setup IntelliJ IDEA for Android App Development 5 min read Guide to Install and Setup Visual Studio for Android App Development 4 min read How to Run the Android App on a Real Device? 2 min read Resolving frequently occurring errors in Android Development 3 min read Android Studio Tutorial 9 min read File Structure & ComponentsComponents of an Android Application 3 min read Introduction to Activities in Android 6 min read Services in Android with Example 10 min read Core TopicsHow Does Android App Work? 7 min read Activity Lifecycle in Android with Demo App 9 min read Introduction to Gradle 4 min read What is Context in Android? 9 min read Bundle in Android with Example 6 min read Activity State Changes In Android with Example 6 min read Processes and Application Lifecycle in Android 7 min read Desugaring in Android 4 min read Difference Between AndroidX and Android Support Libraries 3 min read Memory Leaks in Android 7 min read Layout & ViewLayouts in Android UI Design 3 min read Android UI Layouts 5 min read LinearLayout and its Important Attributes with Examples in Android 3 min read Android LinearLayout in Kotlin 2 min read Android RelativeLayout in Kotlin 4 min read ConstraintLayout in Android 6 min read TextView widget in Android with Examples 5 min read TextView in Kotlin 3 min read Working With the TextView in Android 7 min read Autosizing TextView in Android 6 min read ButtonButton in Android 3 min read How to Add Radio Buttons in an Android Application? 5 min read RadioButton in Kotlin 4 min read How to add Toggle Button in an Android Application 3 min read ToggleButton in Kotlin 2 min read RadioGroup in Kotlin 3 min read Intent and Intent FiltersWhat is Intent in Android? 4 min read Implicit and Explicit Intents in Android with Examples 6 min read How to Send Data From One Activity to Second Activity in Android? 7 min read How to open dialer in Android through Intent? 3 min read Creating Multiple Screen Applications in Android 6 min read How to Open Camera Through Intent and Display Captured Image in Android? 6 min read Toast & RecyclerViewToasts for Android Studio 2 min read What is Toast and How to Use it in Android with Examples? 6 min read Android Toast in Kotlin 3 min read How to Change Toast font in Android? 3 min read How to add a custom styled Toast in Android 4 min read RecyclerView in Android with Example 7 min read Android | Horizontal RecyclerView with Examples 4 min read How to create a nested RecyclerView in Android 5 min read How to Create RecyclerView with Multiple ViewType in Android? 6 min read RecyclerView using ListView in Android With Example 5 min read Like