Creating BeatBox
Open the newly renamed fragment_beat_box.xml. Delete the existing contents of the file. Then fill it
up like so:
Listing 20.1 Reworking main layout file
(res/layout/fragment_beat_box.xml)
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Now create a new Fragment called BeatBoxFragment in com.bignerdranch.android.beatbox.
Listing 20.2 Creating BeatBoxFragment (BeatBoxFragment.java)
public class BeatBoxFragment extends Fragment {
public static BeatBoxFragment newInstance() {
return new BeatBoxFragment();
}
}
For now, leave it empty.
Next, create the BeatBoxActivity your new fragment should go in. You will use the same
SingleFragmentActivity architecture you used in CriminalIntent.
First, use your favorite file explorer or terminal application to copy SingleFragmentActivity.java
from CriminalIntent into BeatBox/app/src/main/java/com/bignerdranch/android/beatbox/, and
then copy activity_fragment.xml into BeatBox/app/src/main/res/layout/. (You can pull these
files out of your own CriminalIntent folder or from the solutions. For information on how to access the
solutions files, refer back to the section called Adding an Icon in Chapter 2.)
Next, delete everything in the body of BeatBoxActivity, change it to a subclass of
SingleFragmentActivity, and override createFragment(), like so:
Listing 20.3 Filling out BeatBoxActivity (BeatBoxActivity.java)
public class BeatBoxActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return BeatBoxFragment.newInstance();
}
}