Skip to content

abhineshchandra1234/DataBinding_With_LiveData

Repository files navigation

Data Binding

"Update layout directly through data source"

This project explains how to use Data Binding with LiveData.


DataBinding

  • As the name suggests, the data binding library allows us to bind UI components of the layout with data sources declaratively rather than programmatically.

One-Way DataBinding

  • In one-way data binding, only the data source can update the views on data change, views cannot update the data source.
  • android:text=”@{employee.name}”

One-Way DataBinding


Two-Way DataBinding

  • Both the view and data source are in sync. Every change in view will be reflected on the data source and vice versa.
  • android:text=”@={mainViewModel.nameLiveData}”

Two-Way DataBinding


Agenda

  • we have used one-way data binding to update profile text using LiveData
  • we have shown how to use data variable,layout expressions

One-Way Data Binding

LiveData1 LiveData2


Two-Way Data Binding

two-way1 two-way2


References


📝 License

Copyright 2022 Abhinesh Chandra

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.