Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
An abstract Activity class

165

The CrimeListFragment class has not yet been created. Let’s remedy that.


Right-click on the com.bignerdranch.android.criminalintent package again, select New → Java
Class, and name the class CrimeListFragment.


Listing 8.11  Implementing CrimeListFragment (CrimeListFragment.java)


public class CrimeListFragment extends Fragment {


// Nothing yet


}


For now, CrimeListFragment will be an empty shell of a fragment. You will work with this fragment
later in the chapter.


Now your activity code is nice and tidy. And SingleFragmentActivity will save you a lot of typing
and time as you proceed through the book.


Declaring CrimeListActivity


Now that you have created CrimeListActivity, you must declare it in the manifest. In addition, you
want the list of crimes to be the first screen that the user sees when CriminalIntent is launched, so
CrimeListActivity should be the launcher activity.


In the manifest, declare CrimeListActivity and move the launcher intent filter from CrimeActivity’s
declaration to CrimeListActivity’s declaration.


Listing 8.12  Declaring CrimeListActivity as the launcher activity
(AndroidManifest.xml)


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >















http://www.ebook3000.com

Free download pdf