最近项目想换成MVVMHabit框架,然而这才刚用,我就发现了一个问题,文档关于ViewPager这一块的内容几乎没有,没办法,只好自己去研究了,顺便写个demo让自己和其他人学习学习。我先创建了必备的GuidanceActivity、GuidanceViewModel、GuidanceItemViewModel,还有两个布局文件,代码很简单,这里就不赘述了,直接贴代码:
public class GuidanceActivity extends BaseActivity<ActivityGuidanceBinding, GuidanceViewModel> {
@Override
public int initContentView(Bundle savedInstanceState) {
return R.layout.activity_guidance;
}
@Override
public int initVariableId() {
return BR.viewModel;
}
@Override
public GuidanceViewModel initViewModel() {
return new GuidanceViewModel(this);
}
@Override
public void initViewObservable() {
super.initViewObservable();
}
}
activity的布局文件代码如下:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:binding="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.goldze.mvvmhabit.ui.vm.GuidanceViewModel" />
</data>
<RelativeLayout
android:layout_width=&#