O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, 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 is designed to host a CrimeListFragment. First, let’s set up a view for CrimeListActivity.

A generic fragment-hosting layout

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

Listing 9.7  activity_crime.xml is already generic

<​?​x​m​l​ ​v​e​r​s​i​o​n​=​"​1​.​0​"​ ​e​n​c​o​d​i​n​g​=​"​u​t​f​-​8​"​?​>​ <​F​r​a​m​e​L​a​y​o​u​t​ ​x​m​l​n​s​:​a​n​d​r​o​i​d​=​"​h​t​t​p​:​/​/​s​c​h​e​m​a​s​.​a​n​d​r​o​i​d​.​c​o​m​/​a​p​k​/​r​e​s​/​a​n​d​r​o​i​d​"​ ​ ​a​n​d​r​o​i​d​:​i​d​=​"​@​+​i​d​/​f​r​a​g​m​e​n​t​C​o​n​t​a​i​n​e​r​"​ ...

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