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​"​ ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

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