‫Hello developers.
‫And welcome back.
‫In this video we're going to link this layout with this ViewModel using the data binding I want from
‫you to focus with me here.
‫Inside the ViewModel we have these variables the input name, input email, save or update button,
‫text clear all or delete button text variables that are mutable live data of type string and annotated
‫with at Bindable annotation.
‫These are very important tricks and very important notes you should learn using the data binding library
‫with Viewmodels.
‫Here I'll start with creating a new data variable.
‫I'll name it as contact ViewModel of type ViewModel.
‫Contact ViewModel.
‫I'm creating an instance from this class.
‫Let's move down and start with the first edit text to get the data from this, edit text and assign
‫it to this input name Bindable variable which is of type mutable live data.
‫So please pay attention.
‫The text attribute will define and link this edit text with this input name variable at equals sign.
‫Please pay attention.
‫Don't miss this equal sign when using the edit text contact ViewModel dot input name.
‫So here I am assigning this edit text to this variable named as input name in the ViewModel.
‫When the user enters any name here in the edit text, this input name will be changed automatically
‫in the same way I'll use with the second edit text.
‫So here the text attribute will be at equals to contact ViewModel dot input email.
‫Then I want from you to focus now because I'm going to use two attributes with this buttons.
‫I'll start with the first button and we have on click attribute.
‫We use it before.
‫So I'm going to call at braces.
‫And here I'll start with parentheses I'm going to call this function named as contact ViewModel dot
‫save or update.
‫So here I am calling a function from the view model.
‫It's called Save or Update.
‫Another attribute that I want to add is the text.
‫So here the text will use two way data binding because I'm going to listen for the changes and the change
‫the text according to this function either a saving function or updating function.
‫For that I'm going to use today a two way data binding.
‫And don't miss this equals sign.
‫Many people missed it.
‫Contact ViewModel dot save or update button text.
‫Okay.
‫These are the two attributes for the button using the data binding in the same way, I'm going to use
‫it with a button number two here on click attribute I'll start with at.
‫Use these parentheses I'm going to call this function from the contact view model dot clear all or delete
‫function.
‫Also I'm going to use text at equals to.
‫Please pay attention for this equal sign.
‫And I'm going to use the contact view model dot clear all or delete button text.
‫In this app I'm going to use two attributes binding with the data binding on click and the text attribute.
‫Here I'm calling the correct function.
‫And here I'm calling the correct text to display it inside this button.
‫Also, instead of writing this, you can write contact, view, model, dot, clear all or delete function.
‫But you need to pass the view attribute here okay.
‫So you need to add a view parameter.
‫But using like this writing you can escape the view parameter.
‫In this way, we'll link our layout with the contact view model using the data binding.