5.3.3. Fragment Lifecycle Methods
Like an Activity
, each Fragment
has a lifecycle and provides methods that you can override to respond to lifecycle events. In this app, you’ll override:
• onCreate—This method (which you’ll override in class SettingsFragment
) is called when a Fragment
is created. The QuizFragment
and SettingsFragment
are created when their parent activities’ layouts are inflated, and the DialogFragment
that displays the quiz results is created when you complete a quiz.
• onCreateView—This method (which you’ll override in class QuizFragment
) is called after onCreate
to build and return a View
containing the Fragment
’s GUI. As you’ll see, this method receives a LayoutInflater, which you’ll use to programmatically inflate a Fragment ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.