Android Architecture Components, android binding and LiveData

Viewed 811

I was wondering whether android binding is compatible with live data on conceptual level. There is a simple task: call server after button is clicked. So in my view I have

android:onClick="@{viewmodel::onOrderButtonClick}"

and proper onOrderButtonClick(View) method is defined in ViewModel. But in order to make server call via LiveData I need my Fragment reference (observe() method needs LifecycleOwner instance as first parameter). Of course I cannot hold reference to fragment in my ViewModel. What is the pattern here? Do I really need to implement all event methods in the fragment class and delegate them back into view model class?

1 Answers
Related