Kotlin Android Fragment recyclerView and context issue

老子叫甜甜 提交于 2019-12-04 16:38:33

Move this code

recylerView_Main.layoutManager = LinearLayoutManager(context)
recylerView_Main.adapter = Mainadapter()

from onCreateView to onActivityCreated

override onActivityCreated and place the above code.

There are two things incorrect in your code :

  1. You are trying to access recyclerView even before inflating the View.

  2. The context of a Fragment is null in onCreateView and is usable in between onAttach and onDetach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!