

Fragments enable both orientations to reuse shared elements while also having differences.


Tablet Support - Often within apps, the tablet version of an activity has a substantially different layout from the phone version which is different from the TV version.For example, using the same list across different data sources within an app. Reusing View and Logic Components - Fragments enable re-use of parts of your screen including views and event logic over and over in different ways across many disparate activities.There are many use cases for fragments but the most common use cases include: Within a fragment-oriented architecture, activities become navigational containers that are primarily responsible for navigation to other activities, presenting fragments and passing data. Fragments are standalone components that can contain views, events and logic.Fragments encapsulate views and logic so that it is easier to reuse within activities.Using the support library, fragments are supported back to all relevant Android versions.A Fragment is a combination of an XML layout file and a java class much like an Activity.Here are the important things to understand about fragments: Fragments must be embedded in activities they cannot run independently of activities. A Fragment typically defines a part of a user interface. Public class ItemListFragment extends ListFragment implements LoaderManager.A fragment is a reusable class implementing a portion of an activity. List Fragment ListFragment is an extension of Fragment class provided by Android that simplifies creating a list view screen.Ĭreate a new ItemListFragment class as follows.
