From b80201e982dc69b8fc9dc82b83d45f08a4507c48 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Wed, 11 May 2022 15:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E7=94=A8ViewModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Android引用ViewModel,lifecycle升级版本后,原方法失效 --- demo1/ViewModel.ky | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 demo1/ViewModel.ky diff --git a/demo1/ViewModel.ky b/demo1/ViewModel.ky new file mode 100644 index 0000000..51acab1 --- /dev/null +++ b/demo1/ViewModel.ky @@ -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) + + } +} \ No newline at end of file