Creating Fragments

  • To create the fragment, we have to extend the Fragment class.
  • Fragment is like Activity class.
  • It is not required to implement all the life cycle methods of the fragment but we must implement the onCreate(), onCreateView(), onPause() methods.
  • There are three sub-classes of the fragment which can be extended as follows:
    • DialogFragment : This class is used to create the floating dialog. It is an alternative option to create the dialog.
    • ListFragment : This class displays the list of items which can be managed using the adapter.
    • PreferenceFragment : This class displays the hierarchy of preference object as a list.