O'Reilly logo

Hello, Android, 4th Edition by Ed Burnette

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

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=​ ...

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