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; ...

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.