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

Starting a Game

Switch over to MainFragment.java for a moment. In the previous chapter we wired up the About button to bring up a dialog. Here, we need to set up the code to start a GameActivity class when the user presses the New or Continue button. Adding the following code to the onCreateView() method in MainFragment.java before the return statement will do the trick:

ticTacToev2/src/main/java/org/example/tictactoe/MainFragment.java
 
View​ newButton = rootView.findViewById(R.id.new_button);
 
View​ continueButton = rootView.findViewById(R.id.continue_button);
 
newButton.setOnClickListener(​new​ ​View​.OnClickListener() {
 
@Override
 
public​ ​void​ onClick(​View​ view) {
 
Intent intent = ​new​ Intent(getActivity(), GameActivity.class); ...

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