So, I implemented
public class DriverLoginActivity extends BaseActivity implements Observer
And, onChanged overided.
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
<Button
android:id="@+id/btnLogin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="Login"
android:onClick="@{(v) -> LoginViewModel.onLoginClick()}"
<Button
android:id="@+id/btnRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="Register"
android:onClick="@{(v) -> LoginViewModel.onRegisterClick()}"
Check this https://github.com/MindorksOpenSource/android-mvvm-architecture/tree/master/app/src/main/java/com/mindorks/framework/mvvm/ui/login