整体架构是这样的
MainActivity:
import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import com.feifan.mymvvm.R;
import com.feifan.mymvvm.databinding.ActivityMyMvvmMainBinding;
import com.feifan.mymvvm.model.UserViewModel;
import com.feifan.mymvvm.viewmodel.MainViewModel;
public class MainActivity extends Activity {
ActivityMyMvvmMainBinding activityMainBinding;
MainViewModel mainViewModel;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_my_mvvm_main);
UserViewModel user=new UserViewModel(“wenfeifan”,“password”);