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 CrimeListFragment.onListItemClick(…) for tablets. Instead of starting a new CrimePagerActivity, onListItemClick(…) would get CrimeListActivity’s FragmentManager and commit a fragment transaction that adds a CrimeFragment to the detail fragment container.

The code would look like this:

p​u​b​l​i​c​ ​v​o​i​d​ ​o​n​L​i​s​t​I​t​e​m​C​l​i​c​k​(​L​i​s​t​V​i​e​w​ ​l​,​ ​V​i​e​w​ ​v​,​ ​i​n​t​ ​p​o​s​i​t​i​o​n​,​ ​l​o​n​g​ ​i​d​)​ ​{​ ​ ​ ​ ​/​/​ ​G​e​t​ ​t​h​e​ ​C​r​i​m​e​ ​f​r​o​m​ ​t​h​e​ ​a​d​a​p​t​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.