You need to have public getters in your view model to access the fields from the xml.
public class LoginViewModel extends ViewModel {
private MutableLiveData<UserEntity> userEntity;
//Mandatory zero parameter constructor, if non zero parameter constructor is necessary, a factory needs to be created for the ViewModel
public LoginViewModel() {}
//Option 1: Public getter for the userEntity object
public MutableLiveData<UserEntity> getUserEntity() {
return userEntity;
}
//Option 2: Alternatively a separate getter can be used for different fields of the model class
public String getUserName() {
return userEntity.getValue().getName();
}
}
Then you can access fields in the xml like this:
Option 1:
android:text="@{userEntityViewModel.user.name}"
Option 2:
android:text="@{userEntityViewModel.userName}"
Hope it helps.