‫When having data classes that should be displayed as objects inside items of the recycler view, you
‫should use the data variables inside the layout tag so I will move these namespaces.
‫To hear.
‫The lay out tag.
‫Press, Ctrl shift, alt and click run and you can see the code is formatted and reformatted to more
‫pretty code.
‫Now.
‫I need to add the variable, the data variable tag here.
‫In order to specify that this card to view each card view, should get the data from the model class
‫called Journal.
‫I will start with data and I will end with the closing tag.
‫I will start with the variable tag and I will name it as journal.
‫The type is com dot master coding dot journal app dot journal.
‫So I am referring to this variable called journal and this data class.
‫Now I will set for every widget inside this cardview and this layout.
‫The corresponding data that should be displayed in this text view, this button, this image view or
‫other widgets for the text view here called Journal row user name.
‫We were.
‫Using the unbind, the Viewholder and the Viewholder class.
‫My viewholder class to to find the view by ID and set everything correctly.
‫Using these codes.
‫Now, by using the data binding, we are using the correct and the specific things as one object, as
‫a data binding object, and it's more faster and more smooth.
‫And they will not create nullable things, nullable objects or any unexpected error in layout designing.
‫So.
‫What we were doing in the Viewholder class.
‫We will do it with single single quotes here in the layout and more and more professional development
‫and code writing.
‫We use it before and when we were talking about the data binding.
‫So inside this text view.
‫I will change the text attribute using the title from this journal.
‫Variable.
‫Do.
‫Please pay attention, guys.
‫At.
‫This opening variable and journal referring to the variable that we have created here.
‫And dot what I need from this to be displaying here inside this text view called title.
‫I need to display the title.
‫Or the username because I'm using the user name here.
‫Given a row username.
‫User name.
‫Okay.
‫There is an error.
‫If I cannot find the identifier, if I clean the project and rebuild the project.
‫And you can see the error still persist here.
‫If I access the journal dot user name, I'm accessing this object, but I need to to get the username
‫variable and attribute.
‫Here you can see we have initialized this as private, so I will remove the private keyword and let
‫me go back and you can see that the error is gone.
‫And we will apply this method for all the texts here.
‫Okay, but let me check this image button.
‫You can see this is the image button.
‫I can set the resource as a share button.
‫If I scroll down, you can see there is an image view and this image view I will set Android background
‫and here I will specify.
‫Using the data binding at.
‫And here I will put journal dot.
‫Image URL.
‫Okay.
‫And here there is an error because the image URL must be an integer.
‫And you can see at the data class we have created the image view the image URL as string, we change
‫it to URL.
‫Image URL type to integer and everything will work fine.
‫Again, I need to go down to here.
‫Journal title list.
‫I will change this text to at.
‫Journal.
‫Dot.
‫Title.
‫The Journal Thoughts.
‫Blessed as.
‫At.
‫Journal dot Thoughts.
‫And here, the timestamp.
‫Last is at journal dot time.
‫It.
‫But you can see there is an error.
‫I can't change this timestamp to a variable of type string unless I can use to string.
‫Okay.
‫It's very simple.
‫So this is how we add the data binding to our layout.