MainVM
class MainVM: ViewModel() {
var content = ObservableField()
var textContent = ObservableField()
}
布局文件
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
name="vm"
type="com.xiangxue.mvx.mvvm.MainVM" />
name="presenter"
type="com.xiangxue.mvx.mvvm.MainPresenter" />
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@{vm.textContent}" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{vm.content}" />
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="@={vm.content}" />
添加点击方法
class MainPresenter {
fun show(mainVM: MainVM){
mainVM.textContent.set(mainVM.content.get())
}
}