As the headline says: Is it possible to get the currently visible fragment with all UI elements initialized within the onCreate() method of the activity? I am implementing a sep
By default, no. At the time activity onCreate()
runs, the fragment is not attached to the activity yet.
Right place to access a fragment's views is in the fragment itself. Consider putting the controller assignments in the fragment within its lifecycle such as onCreateView()
or onViewCreated()
.
It is possible to explicitly run queued up fragment transactions using executePendingTransactions(), or implicitly after super.onStart()
has been run in the activity lifecycle. After that the fragment views are accessible in the activity view hierarchy.