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.
I'm a big fan of your tutorials)) Also, I've added one more imageView in the XML and created a Binding Adapter. Using that, I'm loading an image using Glide. And for the image URL, I've created an Object, where I store my URL. Then I imported that Constants Object inside XML as and used the URL inside that object to load the image.
How @bindable is working in viewmodel??....when I use same like your code ...it reflecting error.....same issue is raised in stackover flow ....no need to use @bindable just @={viewmodel.edittext} is enough...it will update edittext field in viewmodel.
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,
Thank you for your great tutorials! I noticed you are using AndroidX package which I had no idea what it was until your tutorial :) Now that this AndroidX package is 1.0.0 production ready as of 21st September, is it recommended to use these over the android.support* packages? Reason I'm also asking is because when using @Bindable in ViewModel the compiler complains about the class not being of Observable which I suspect there may be changes in the new AndroidX package that I'm yet to try to see if it resolves this error...
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.
Great tutorial, thanks. I have a question though, imagine we wanted to do something else besides modifying 'editTextContent'. For example store in the database every change (just theoretical example). I don´t want an observer observe the field from the Activity, because this is a business action, nothing to do with the view. How could i do this? Is it possible to customize the way the value is set, maybe with a setter method or similar?
I have the same issue, I just noticed the use of the AndroidX package which is something new to me that I only found out about today. I'm wondering if ViewModel has changed in these new packages.
Actually it's not so much difficult to fix it. I've just created my own ObservableViewModel class which extends the Observable class, and used it in my viewmodel. Then it worked!
Its not necesari to annotate MutableLiveData with @Bindable, actually MutableLiveData it's not gonna change, just its value and Databinding cares about it
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.
I have downloaded a plugin called "Material Theme UI" and I have chosen the "Material Darker" variant. I'm also using Consolas font because I don't like Fira Sans that comes packaged with the plugin.
Good, but why would you use MutableLiveData if you think its unsafe. Why not teach people how to do the proper way instead of an unsafe way. Seems irresponsible...
It's only as unsafe as the programmer writing the code is irresponsible. There's no way around MutableLiveData when it comes to two-way data binding. That's because the data binding needs to "mutate" the data itself.