O'Reilly logo

Android Programming: The Big Nerd Ranch Guide, Third Edition by Kristin Marsicano, Chris Stewart, Bill Phillips

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

An Abstract Activity for Hosting a Fragment

In a moment, you will create the CrimeListActivity class that will host a CrimeListFragment. First, you are going to set up a view for CrimeListActivity.

A generic fragment-hosting layout

For CrimeListActivity, you can simply reuse the layout defined in activity_crime.xml (which is copied in Listing 8.4). This layout provides a FrameLayout as a container view for a fragment, which is then named in the activity’s code.

Listing 8.4  activity_crime.xml is already generic

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" ...

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