Reputation: 1739
I found kotlin extension
(ktx
) today and tried to use it.
Using this, I tried to create a view model
using by viewmodels()
.
But I heard that KTX
is going to be deprecated soon, is that correct?
Better not to use it?
So, how do i create a view model
in the future?
constructor
? Or ViewModelProvider.get(this)
?
Upvotes: 0
Views: 215
Reputation: 194
Firstly, declare a private lateinit var
private lateinit var viewModel: DetailsViewModel
Then,, please try this code in your fragment's onViewCreated
viewModel = ViewModelProvider(this,factory).get(DetailsViewModel::class.java)
factory is usually injected with yout dependecy injection library
Upvotes: 2