JeroenMols/ModularizationExample

[IMPROVE] You can use androidx.fragment.app.Fragment constructor and pass `R.layout` there instead of overriding `onCreateView` like we used to

rcd27 opened this issue · 2 comments

rcd27 commented

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

Thanks for the suggestion. I'm not aware of this (and can't find it myself), do you have a link to the fitting AndroidX docs?

I do, It was added in 1.1.0 (as seen here: https://developer.android.com/jetpack/androidx/releases/fragment#version_110_3):

FragmentActivity LayoutId constructor: Subclasses of FragmentActivity can now optionally call into a constructor on FragmentActivity that takes an R.layout ID, indicating the layout that should be set as the content view as an alternative to calling setContentView() in onCreate(). This does not change the requirement that your subclass have a no-argument constructor.

Fragment LayoutId constructor: Subclasses of Fragment can now optionally call into a constructor on Fragment that takes an R.layout ID, indicating the layout that should be used for this fragment as an alternative to overriding onCreateView(). The inflated layout can be configured in onViewCreated().