引用ViewModel

Android引用ViewModel,lifecycle升级版本后,原方法失效
This commit is contained in:
yutou 2022-05-11 15:40:40 +08:00
parent 0576846d6c
commit b80201e982

11
demo1/ViewModel.ky Normal file
View File

@ -0,0 +1,11 @@
class CrimeListFragment : Fragment() {
private lateinit var crimeRecyclerView: RecyclerView
private var adapter: CrimeAdapter? = null
private val crimeListViewModel: CrimeListViewModel by lazy {
//ViewModelProvider.of(this).get(CrimeListViewModel::class.java)
ViewModelProvider.AndroidViewModelFactory.getInstance(context?.applicationContext as Application).create(CrimeListViewModel::class.java)
}
}