Q:

Tic-Tac-Toe Draw condition for Android Studio

I am making a Tic Tac Toe application. I had already done with the "win" statement, but I am stuck at the draw statement.
Following are my codes.
public class MainActivity extends AppCompatActivity {

    int activePlayer = 0; // 0 for red
    int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2}; // 2 means unplayed.
    int[][] winningLocations = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8},
            {2, 4, 6}};
    boolean gameOver = false;

    public void gameLogic(View view) {

        ImageView tappedView = (ImageView) view;

        int tappedLocation = Integer.parseInt(view.getTag().toString());

        if (gameState[tappedLocation] == 2 && !gameOver) {

            gameState[tappedLocation] = activePlayer;

            tappedView.setTranslationY(-3000f);

            if (activePlayer == 0) {

                tappedView.setImageResource(R.drawable.red);
                activePlayer = 1;

            } else if (activePlayer == 1) {

                tappedView.setImageResource(R.drawable.yellow);
                activePlayer = 0;

            }

        tappedView.animate().translationYBy(3000f).setDuration(500);

        String msg = "";

        for (int[] winningPosition : winningLocations) {

            if (gameState[winningPosition[0]] == gameState[winningPosition[1]]
                    && gameState[winningPosition[1]] == gameState[winningPosition[2]]
                    && gameState[winningPosition[0]] != 2) {

                if (activePlayer == 0)
                    msg = "Yellow is Winner!";

                if (activePlayer == 1)
                    msg = "Red is Winner!";

                LinearLayout winnerLayout = (LinearLayout) findViewById(R.id.winnerLayout);
                winnerLayout.setVisibility(View.VISIBLE);

                TextView winnerMsg = (TextView) findViewById(R.id.textView);
                winnerMsg.setText(msg);

                gameOver = true;
            }
        }
    }

}

    public void playAgain(View view){

        LinearLayout winnerLayout = (LinearLayout)findViewById(R.id.winnerLayout);
        winnerLayout.setVisibility(View.INVISIBLE);

        gameOver = false;
        activePlayer = 0;

        for(int i = 0; i < gameState.length; i++)
            gameState[i] = 2;

        GridLayout gridLayout = (GridLayout)findViewById(R.id.gridLayout);
        for(int i = 0; i < gridLayout.getChildCount(); i++)
            ((ImageView)gridLayout.getChildAt(i)).setImageResource(0);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        LinearLayout winnerLayout = (LinearLayout) findViewById(R.id.winnerLayout);
        winnerLayout.setVisibility(View.INVISIBLE);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
}

A:

Assuming a draw in tic-tac-toe is all 9 squares filled with no line of 3 found, I'd put something like this after the for loop that checks for a winning condition:
boolean emptySquare = false;
for (int squareState : gameState) {
  if (squareState == 2) {
    emptySquare = true;
    break;
  }
}

if (!emptySquare && !gameOver) {
  // Game is a draw
  gameOver = true;
  // Set draw message here...
}

