Lab 4 Pig Game with Fragments Solution




Purpose: This lab is designed to give you practice:


  • Using fragments to adapt your app to large and small screen sizes.


  • Giving multiple fragments access to a single object (an instance of your game class).


Part 1: Do the textbook exercises shown below:


  • 9-1, Test the Tip Calculator with fragments
  • 9-2, Create a new fragment


  • 9-3, Use the fragment manager


Upload a text file to Canvas in which you will report, for each exercise above, whether you:


  1. Followed all the steps shown in the book and successfully compiled and ran the program (where applicable).
  2. Loaded the completed solution, experimented with the code, and ran the program (where applicable).
  3. Read through the steps and inspected the relevant code listings without writing or running a program.
  4. Didn’t do any of the above.


Part 2: Pig Game v3.


In this lab you will modify your app to use fragments. You will have four fragments:


  1. An opening screen that displays instructions and asks the players for their names. It will have a “New Game” button that launches fragment 2.
  2. The UI for game-play (similar to the main activity in the previous lab). The up button on will take the user back to the opening screen.


  1. An about dialog which is displayed by clicking the “About” item on the menu.


  1. The settings screen which is displayed by clicking the “Settings” item on the menu.



On a small screen, or in portrait orientation, only one of these two fragments will be displayed at a time, each in it’s own activity.


On a large screen, or in landscape orientation, both fragments will be displayed side-by-side in one activity.


The up button will only be needed when fragment 2 is displayed by itself in a separate activity.



The Settings and Menu fragments will always be displayed by themselves. You can put a menu on both fragments 1 and 2, or on just fragment 1.


The names of the players will need to be passed from fragment 1 to fragment 2, the player’s name for the current turn will need to be displayed in the second fragment. Fragment 2 will hold the game object.


Zip the project and upload it to Canvas.



error: Content is protected !!