Call View Model method from xml not invoke Issue in android

  android, kotlin, mvvm, viewmodel, xml
    **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" />
         ....
         ......
         .......

View Model Class implementation where on click for invoke method

 class HomeViewModel : ViewModel() {
    
        var isProfileClick: MutableLiveData<Boolean> = MutableLiveData()
    
       fun onProfileClick(view:View) {
            isProfileClick.value = true
        }
    
    }

How to invoke method for imageView on click in MVVM to invoke viewModel method

Source: Android Questions

LEAVE A COMMENT