'Is it Okay to use on click in view model?

I am using navigation component and I want to traverse from one fragment to another so is it okay if I used it like below

fun customClick(view: View) {
        view.apply {
            when (id) {
                R.id.icon -> findNavController().navigate(R.id.action_name)      
            }
        }
    }

and I use this method with databinding in my activity like below

android:onClick="@{(view)->viewmodel.customClick(view)}"

I know view model is designed to store and manage UI-related data. So Is it good practice to work like above code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source