I want to make onClick()
in my layout xml trigger two methods from two viewmodels.
Code:
<Button
android:onClick="@{() -> model.onButtonClick()}"
... />
The above code calls one method, I want it to call another one in from a different viewmodel.
Function call I want to add: model2.onButtonClick()
Is it possible? If yes, kindly add an minimal example. (Expecting a xml solution)
Note: Viewmodels are passed as arguments in xml. (data-binding variables)
Edit 1: Both functions are in two different view models. So I (after some research) know that using/declaring/initializing one view model inside another is not a good practise.
I could create a click listener inside my fragment and call both functions there. But I want to eliminate click listener in fragments (views as per MVVM).
I am not looking for some possible way. I am searching for a best practise method, where I intend to implement MVVM, seperation of concerns and data-binding.