With the stabilization of Android Architecture Components I started updating all my basic ViewModel
s to the new implementation ofViewModel. In my understanding,
The accepted answer does not give an example. So here's one I've tested and it works.
In layout:
...
...
In fragment:
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding: FragmentAlbumBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_album, container, false)
binding.apply {
fragment = this
viewModel = albumViewModel
lifecycleOwner = this
}
}