Introducing Fragments

You can ensure that your app is flexible by moving the app’s UI management from the activity to one or more fragments.

A fragment is a controller object that an activity can deputize to perform tasks. Most commonly, the task is managing a UI. The UI can be an entire screen or just one part of the screen.

A fragment managing a UI is known as a UI fragment. A UI fragment has a view of its own that is inflated from a layout file. The fragment’s view contains the interesting UI elements that the user wants to see and interact with.

Instead of containing the UI, the activity’s view can hold a container for the fragment. The fragment’s view is inserted into the container once it is inflated. In this chapter, the ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.