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

Creating a ListFragment

Create a new class named CrimeListFragment. Click Browse to choose a superclass. Search for and select ListFragment – android.support.v4.app and then click Finish to generate CrimeListFragment.

ListFragment was introduced in Honeycomb, but it is duplicated in the support library. So compatibility is not a problem as long as you use the support library class, android.support.v4.app.ListFragment.

In CrimeListFragment.java, override onCreate(Bundle) to set the title of the activity that will host this fragment.

Listing 9.4  Adding onCreate(Bundle) to the new activity (CrimeListFragment.java)

p​u​b​l​i​c​ ​c​l​a​s​s​ ​C​r​i​m​e​L​i​s​t​F​r​a​g​m​e​n​t​ ​e​x​t​e​n​d​s​ ​L​i​s​t​F​r​a​g​m​e​n​t​ ​{​

 ​ ​ ​ ​@​O​v​e​r​r​i​d​e​ ...

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