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

Filling In the Code

Now that we have the layouts of the main screen and fragment, we need to write a little Java code to make them appear. We’ll start with the app’s main program: the MainActivity class.

Defining the Main Activity

You should already have a file called MainActivity.java in the org.example.tictactoe package under the java folder. It was created by Android Studio when we created the project. Open it now by double-clicking it in the Project window, by selecting the Navigate > File menu option, or by pressing the keyboard shortcut (Ctrl+Shift+N on Windows) and typing the filename. Then replace all the code with the following:

ticTacToev1/src/main/java/org/example/tictactoe/MainActivity.java
Line 1 
package​ org.example.tictactoe; ...

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