O'Reilly logo

Android 5 Programming by Example by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Applying Fragments

Using two or more Activities to create separate screens is a straightforward way to include multiple pages in our apps. However, it is not the only method, and the system also provides the Fragment classes. Fragments are similar to ViewGroups; in that they exist as part of an Activity, but the way that they are created and destroyed makes them behave more like mini Activities. Unlike Activities, we can also have more than one Fragment to a screen.

There are two ways to deploy Fragments in an Android app. Firstly they can be added directly to our layout XML files with the <fragment> tag and they can also be added and removed dynamically at run time. Although we will now look at both these techniques, it is the second, dynamic ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required