【发布时间】:2021-05-25 20:23:03
【问题描述】:
**The XMl file where from calling method of view Model**
<variable
name="viewModelDetail"
type="com.joyor.viewmodel.HomeViewModel" />
</data>
<ImageView
android:id="@+id/profile"
android:layout_width="@dimen/_30sdp"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/_5sdp"
android:onClick="@{viewModelDetail.onProfileClick}"
android:padding="@dimen/_5sdp"
android:src="@drawable/ic_profile"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
....
......
.......
点击调用方法查看模型类实现
class HomeViewModel : ViewModel() {
var isProfileClick: MutableLiveData<Boolean> = MutableLiveData()
fun onProfileClick(view:View) {
isProfileClick.value = true
}
}
如何在MVVM中调用imageView的方法来调用viewModel方法
【问题讨论】:
标签: android xml kotlin mvvm viewmodel