How can I make separate code on onChanged() while observing with LiveData in MVVM? [Not solved]

后端 未结 1 382
一生所求
一生所求 2021-01-28 01:30

So, I implemented

public class DriverLoginActivity extends BaseActivity implements Observer

And, onChanged overided.

1条回答
  •  梦毁少年i
    2021-01-28 01:57

    In MVVM, the ViewModel is designed to manage data. The ideal way would be handling your API calls in the ViewModel. Using LiveData for this is not the ideal use of LiveData.

    Your ViewModel can have

    public void onLoginClick(View view) {
        //Implement Login API call here
    }
    
    
    public void onRegisterClick(View view){
        //Implement Register API call here
    
    }
    

    And in your activity_main.xml

    Check this https://github.com/MindorksOpenSource/android-mvvm-architecture/tree/master/app/src/main/java/com/mindorks/framework/mvvm/ui/login

    0 讨论(0)
提交回复
热议问题