I was recently told that Google likes Medium, so I’ve started posting there. Here’s a quick intro to using data binding in its most basic form:
I was recently told that Google likes Medium, so I’ve started posting there. Here’s a quick intro to using data binding in its most basic form:
Data binding is great! I’ve managed to implement a nice MVVM approach that I’m quite pleased with. But I find something very useful is lacking – binding for option and toolbar menus. Any plans to add support for these? Would be great if it was possible to bind a menu item to its own ViewModel that controls a separate item in the menu. I mean its entire state – visibility, title, command, isChecked. Currently I don’t see a simple way to make a custom binding adapter to achieve such behavior. The problem is that in MVVM the ViewModel is forbidden to communicate to the View except through the binding mechanism.
I like this idea.
LOL, Google like Medium…they should like documentation, why is this stuff not in the data binding docs?
Hi George,
My android code is full of generics GenericBindingAdapter , GenericArrayAdapter
==>
==>GenericModel i am using wild card to catch any type which is a valid syntax,
however i dont understand why it gives the error “?” type not found , generics do work this way , it is not necessary for me to see wild card type in intellisence which is for developer comfort , can you share any work around for this issue
Data binding doesn’t support wildcards in generics. You can always use Object as the type.
Hi George,
I am following your articles on DataBinding on Medium and I have got a head start on this.
My Project Fragment Navigation is controlled by Parent Fragment or Activity through interfaces. How I can achieve this in MVVM ? Do I have to open new Fragment from ViewModel or View ?
You want to achieve fragment navigation through a View Model? Normally I recommend having the View Model contain the data and have a separate class control the callbacks, just for separation of concerns. In any case, fragment navigation can be achieved using the callbacks. Assuming you have a button associated with the UI that causes the navigation, you might have something like this:
And your handler would be something like this: