{"id":21243551,"url":"https://github.com/umesh-patidar/android-data-binding","last_synced_at":"2026-04-28T13:39:09.942Z","repository":{"id":177917785,"uuid":"220944861","full_name":"Umesh-Patidar/Android-Data-Binding","owner":"Umesh-Patidar","description":"Tutorial about Android data binding","archived":false,"fork":false,"pushed_at":"2024-07-28T15:30:31.000Z","size":3143,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T20:08:52.904Z","etag":null,"topics":["android","android-application","databinding","databinding-android","java","twoway-data-binding"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Umesh-Patidar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-11T09:25:02.000Z","updated_at":"2024-07-28T15:35:39.000Z","dependencies_parsed_at":"2023-07-11T00:15:07.306Z","dependency_job_id":null,"html_url":"https://github.com/Umesh-Patidar/Android-Data-Binding","commit_stats":null,"previous_names":["umesh-patidar/android-data-binding"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Umesh-Patidar","download_url":"https://codeload.github.com/Umesh-Patidar/Android-Data-Binding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243682698,"owners_count":20330468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-application","databinding","databinding-android","java","twoway-data-binding"],"created_at":"2024-11-21T01:12:45.612Z","updated_at":"2026-04-28T13:39:04.921Z","avatar_url":"https://github.com/Umesh-Patidar.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Android Data Binding [One way]\n\n# Overview\n\nAndroid has now released a stable data-binding library which allows you to connect views with data in a much more powerful way than was possible  previously. Applying data binding can improve your app by removing boilerplate for data-driven UI and allowing for two-way binding between views and data objects. This provides a way to tie the UI with business logic allowing the UI values to update automatically without manual intervention. This reduces lot of boilerplate code in your business logic that you usually write to sync the UI when new data is available. DataBinding is one of the android architecture components suggested by android\n\n\n# Setup\nTo enable the usage of data binding in your Android application, add the following snippet to the app/build.gradle file.\n\n```\n android {\n     dataBinding.enabled = true\n     }\n```\n\n# Binding data\n\nA binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is **activity_main.xml** so the corresponding generated class is **ActivityMainBinding**.\n\n# Layouts and binding expressions\n\nThe expression language allows you to write expressions that connect variables to the views in the layout. The Data Binding Library automatically  generates the classes required to bind the views in the layout with your data objects.\n\nFor example, the binding variables that can be used in expressions are defined inside a data element that is a sibling of the UI layout's root element. Both elements are wrapped in a layout tag, as shown in the following example:\n\n```\n\u003clayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n        xmlns:app=\"http://schemas.android.com/apk/res-auto\"\u003e\n    \u003cdata\u003e\n        \u003cvariable\n            name=\"viewmodel\"\n            type=\"com.myapp.data.ViewModel\" /\u003e\n    \u003c/data\u003e\n    \u003cConstraintLayout... /\u003e \n\u003c/layout\u003e\n```\nThe usage of data binding requires changes in your layout files. Such layout files starts with a **layout** root tag followed by a **data** element and a **view root element**. The **data** elements describe data which is available for binding. This view element contains your root hierarchy similar to layout files which are not used with data binding. References to the data elements or expressions within the layout are written in the attribute properties using the **@{} or @={}**.\n\n# Data binding for events via listener\n\nEvents may be bound to handler methods directly, similar to the way android:onClick can be assigned to a method in the activity. Event attribute names are governed by the name of the listener method with a few exceptions. For example, View.OnLongClickListener has a method onLongClick(), so the attribute for this event is android:onLongClick.\n\nTo assign an event to its handler, use a normal binding expression, with the value being the method name to call. The binding expression can assign the click listener for a View.\n\n\n```\n\u003clayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n        xmlns:app=\"http://schemas.android.com/apk/res-auto\"\u003e\n    \u003cdata\u003e\n        \u003cvariable\n            name=\"itemClickListener\"\n            type=\"com.databinding.custom.CustomClickListener\" /\u003e\n    \u003c/data\u003e\n    \u003cConstraintLayout... /\u003e \n\u003c/layout\u003e\n```\n# Attached listener in layout\nyou can bind the listener using below tag.\n\n```\nandroid:onClick=\"@{() -\u003e itemClickListener.cardClicked(dataModel)}\"\n```\n\u003e Example:\n```\n\u003candroidx.cardview.widget.CardView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_margin=\"5dp\"\n        android:onClick=\"@{() -\u003e itemClickListener.cardClicked(dataModel)}\"\n        app:cardUseCompatPadding=\"true\"\u003e\n\n\u003c/androidx.cardview.widget.CardView\u003e\n```\n\n# End Result\n\u003cimg src=\"https://github.com/Umesh-Patidar/Android-Data-Binding/blob/master/data_binding.gif\" width=\"200\" height=\"400\"/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding/lists"}