{"id":21243545,"url":"https://github.com/umesh-patidar/android-data-binding-two-way","last_synced_at":"2026-04-29T19:01:41.847Z","repository":{"id":177917804,"uuid":"221134365","full_name":"Umesh-Patidar/Android-Data-Binding-Two-Way","owner":"Umesh-Patidar","description":"Tutorial about Two way data binding with example","archived":false,"fork":false,"pushed_at":"2019-11-15T11:15:46.000Z","size":4107,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-01T23:18:02.607Z","etag":null,"topics":["android","android-application","application","databinding","databinding-android","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-12T05:07:43.000Z","updated_at":"2024-07-28T15:34:52.000Z","dependencies_parsed_at":"2023-07-11T00:15:23.586Z","dependency_job_id":null,"html_url":"https://github.com/Umesh-Patidar/Android-Data-Binding-Two-Way","commit_stats":null,"previous_names":["umesh-patidar/android-data-binding-two-way"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Umesh-Patidar/Android-Data-Binding-Two-Way","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding-Two-Way","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding-Two-Way/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding-Two-Way/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding-Two-Way/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-Two-Way/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umesh-Patidar%2FAndroid-Data-Binding-Two-Way/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32439301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T18:12:22.909Z","status":"ssl_error","status_checked_at":"2026-04-29T18:11:33.322Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","application","databinding","databinding-android","twoway-data-binding"],"created_at":"2024-11-21T01:12:45.075Z","updated_at":"2026-04-29T19:01:41.840Z","avatar_url":"https://github.com/Umesh-Patidar.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Android-Data-Binding-Two-Way \n\n# Overview\nData binding allows to synchronize your user interface with your application model and logic. Two-way Data Binding works in the same way as regular, [One Way](https://github.com/umesh151988/Android-Data-Binding/blob/master/README.md) Data Binding. Using one-way data binding, you can set a value on an attribute and set a listener that reacts to a change in that attribute.In Two way the @={} notation, which importantly includes the \"=\" sign, receives data changes to the property and listen to user updates at the same time.\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\u003e In order to react to changes in the backing data, you can make your layout variable an implementation of Observable, usually **BaseObservable**, and use a **@Bindable** annotation, as shown in the following code snippet:\n\n # Updating UI using Observables\n\nObservables provides way to automatically sync the UI with data without explicitly calling setter methods. The UI will be updated     when the value of a property changes in an object. To make the object observable, extend the class from BaseObservable.\n\n - To make a property observable, use @Bindable annotation on getter method.\n - Call notifyPropertyChanged(BR.property) in setter method to update the UI whenever the data is changed.\n - The BR class will be generated automatically when data binding is enabled.\n\n\n```\npublic class UserData extends BaseObservable {\n    private String email;\n    private String password;\n    private Context context;\n\n    public UserData(Context context) {\n        this.context = context;\n    }\n\n    @Bindable\n    public String getEmail() {\n        if (email == null) {\n            return \"\";\n        }\n        return email;\n    }\n\n    public void setEmail(String email) {\n        this.email = email;\n        notifyPropertyChanged(BR.email);\n    }\n}\n```\n# Two-way data binding using custom attributes\n\n\u003eTwo-way attributes\n\nThe platform provides built-in support for two-way data binding when you use the attributes in the following table\n\n| Class         \t| Attribute(s) \t                | Binding adapter             |\n| ---            | ---                           | ---                         |\n| AdapterView    | \tandroid:selectedItemPosition | AdapterViewBindingAdapter   |\n|     ---        | \t android:selection \t         | \t  ---                      |\n| CalendarView \t |   android:date \t              | CalendarViewBindingAdapter  | \n| CompoundButton |   android:checked            \t| CompoundButtonBindingAdapter| \n| DatePicker     | \t android:year                | DatePickerBindingAdapter   \t| \n|      ---       | \t android:month               | \t---                       \t|\n|     ---        |   android:day                 | \t---                        |\n\n\nIf you want to use two-way data binding with custom attributes, you need to work with the **@InverseBindingAdapter** and **@InverseBindingMethod** annotations.\n\nFor example, if you want to enable two-way data binding on a \"time\" attribute in a custom view called MyView, complete the following steps:\n\n```\n1. Annotate the method that sets the initial value and updates when the value changes using @BindingAdapter\n\n@BindingAdapter(\"time\")\npublic static void setTime(MyView view, Time newValue) {\n    // Important to break potential infinite loops.\n    if (view.time != newValue) {\n        view.time = newValue;\n    }\n}\n\n2. Annotate the method that reads the value from the view using @InverseBindingAdapter:\n\n@InverseBindingAdapter(\"time\")\npublic static Time getTime(MyView view) {\n    return view.getTime();\n}\n\n```\n\n# Difference \n\n| Values         \t       | One Way\t                      | Two way                     |\n|         ---            |       ---                     |      ---                    |\n| Communication         \t| It’s named one-way databinding because there’s only one communication way: from observable to view               | There are two communication ways: from observable to view and viceversa              |\n| Symbol                \t| @{}                           |  @={}                       |\n| annotation             |       ---                     |  @Bindable                  |\n| setter method          |       ---                     |  notifyPropertyChanged(BR.property)| \n\n\n# End Result\n![Optional Text](../master/data_binding_two_way.gif)\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding-two-way","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding-two-way","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumesh-patidar%2Fandroid-data-binding-two-way/lists"}