Controlling the Game

While playing the game, the user might want to start over or go back to the main menu. Of course, users can press the Back button to go back, but since some people have trouble finding the Back button we’ll provide a way to return on screen.

Let’s start with a fragment containing a button for “Restart” and one for “Main Menu”:

ticTacToev2/src/main/res/layout/fragment_control.xml
 
<LinearLayout
 
xmlns:android=​"http://schemas.android.com/apk/res/android"
 
xmlns:tools=​"http://schemas.android.com/tools"
 
android:layout_width=​"wrap_content"
 
android:layout_height=​"wrap_content"
 
android:orientation=​"horizontal"
 
android:padding=​"@dimen/control_padding"
 
tools:context=​".GameActivity"​​>
 
 
<Button
 
android:id=​ ...

Get Hello, Android, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.