Android

Data Binding with LiveData (Two-way & One-way) – Android Kotlin Tutorial

📗 Get the code written in this tutorial 👇👇 https://resocoder.com/data-binding-livedata Start saving time now by planning weekly with Week Sweep: http://bit.ly/2Jf3QA0 Managing...



📗 Get the code written in this tutorial 👇👇
https://resocoder.com/data-binding-livedata

Start saving time now by planning weekly with Week Sweep: http://bit.ly/2Jf3QA0

Managing the layout programmatically can be quite time consuming and verbose on Android. Even though Kotlin spares you of calling findViewById, accessing views in the activity code can still get ugly. When you use data binding, you can do most of the UI related stuff right in the XML layouts.

With LiveData, data binding becomes even more powerful and simple to use. While you could create observable fields even in the past when LiveData didn’t exist, this new life-cycle aware observable makes data binding even better and simpler.

In this tutorial you are going to learn how to use one-way and two-way data binding with LiveData and MVVM architecture.

Go to my website for more information, code examples and articles:
● http://resocoder.com

Follow me on social media:
● https://www.facebook.com/resocoder
● https://twitter.com/resocoder

source

26 Replies to “Data Binding with LiveData (Two-way & One-way) – Android Kotlin Tutorial”

  1. Hi , I have just one doubt , if we have a dataclass having 2 field name and address and that is intialised with Live data then how can we achieve 2 way binding for that,

  2. Hi, could you please help me. When I try to bind mutablelivedata-string variable it works fine and I can observe any changes in the activity, however, when I try to bind mutablelivedata of custom model type, I am unable to observe any change to the value of the custom model attribute in my activity.

  3. I like your explanation style. I couldn't quite get the repository to build, but I was able to transplant the code into another project and run it. I watched quite a lot of videos on two-way binding and read a lot of tutorials, but yours was the clearest and had code I could use. I'll be looking for other topics, like recycleview with databinding, preferably in Kotlin.

  4. You're holding on to the same state – currentRandomFruitName – in two different places while trying to synchronise between them. There should be a law against that.

Beri komentar...