Cannot resolve ViewModelProvider construction in a fragment?

后端 未结 4 1793
悲哀的现实
悲哀的现实 2021-02-19 05:28

I have been spending a lot of time trying to figure out why in the code below (towards the end), I get an error on ViewModelProvider(this). I also tried getActivity() instead of

4条回答
  •  情歌与酒
    2021-02-19 06:00

    You should instantiate your viewModel by :

    ItemSetupFragmentModel model = ViewModelProviders.of(this).get(ItemSetupFragmentModel.class);
    

提交回复
热议问题