O'Reilly logo

Android Programming: The Big Nerd Ranch Guide, Third Edition by Kristin Marsicano, Chris Stewart, 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

Activity: Fragment Boss

Now that your layouts are behaving properly, you can turn to adding a CrimeFragment to the detail fragment container when CrimeListActivity is sporting a two-pane layout.

You might think to simply write an alternative implementation of CrimeHolder.onClick(View) for tablets. Instead of starting a new CrimePagerActivity, this onClick(View) would get CrimeListActivity’s FragmentManager and commit a fragment transaction that adds a CrimeFragment to the detail fragment container.

The code in your CrimeListFragment.CrimeHolder would look like this:

public void onClick(View view) { // Stick a new CrimeFragment in the activity's layout Fragment fragment = CrimeFragment.newInstance(mCrime.getId()); FragmentManager ...

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