Android: Where to put activity's onCreate() code in a fragment?

后端 未结 2 2107
旧时难觅i
旧时难觅i 2020-12-14 03:17

I\'m converting all my Activities to Fragments so that I can use them in a ViewPager.

I\'ve searched for this but I couldn\'t find a satisfying answer, so that\'s wh

2条回答
  •  半阙折子戏
    2020-12-14 04:04

    1.Left the onCreate empty and just call super.onCreate()

    2.Instead of findViewById() use getActivity().findViewById() always use getActivity() where you need context of the view.

     Do all other operations in onCreateview()
    

提交回复
热议问题