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