We come across some onCreateView initialization in onCreateView .
You must inflate your layout in onCreateView but you must not initialize other views using findViewById in onCreateView .
Because sometimes the view is not properly initialized. Therefore, always use findViewById in onViewCreated (when the view is fully created), and it also passes the view as a parameter.
onViewCreated - make sure the view is fully created.
onViewCreated Android documentation
Called immediately after onCreateView ( android.view.LayoutInflater, android.view.ViewGroup , android.os.Bundle ), but before restoring any saved state in the view. This gives subclasses the ability to initialize themselves as soon as they find out that their presentation hierarchy is fully created. However, at this stage, the fragment presentation hierarchy is not tied to its parent.
Xar E Ahmer Aug 02 '16 at 10:40 2016-08-02 10:40
source share