Q:

Using if Manipulation / method on button array

I am trying to create a TIC TAC TOE application in Android.
I have created a array of buttons
 public Button buttons[] = null;

In the onCreate() method I fetch the Buttons from the XML file.
    buttons[0] = (Button) findViewById(R.id.button9);
    buttons[1] = (Button) findViewById(R.id.button3);
    buttons[2] = (Button) findViewById(R.id.button4);
    buttons[3] = (Button) findViewById(R.id.button8);
    buttons[4] = (Button) findViewById(R.id.button);
    buttons[5] = (Button) findViewById(R.id.button5);
    buttons[6] = (Button) findViewById(R.id.button7);
    buttons[7] = (Button) findViewById(R.id.button2);
    buttons[8] = (Button) findViewById(R.id.button6);

For each button, there is a different function. For example
    public void midBTMCLicked(View arg0) {

    if (Clicked == true) {
        buttons[7].setBackgroundResource(R.drawable.x);
        Clicked = false;
    } else {
        buttons[7].setBackgroundResource(R.drawable.o);
        Clicked = true;

    }
    buttons[7].setEnabled(false);
    Log.i("buttonCLicked","button middle at the lower line clicked,");
}

and now, after i  wrote the code of the Onclick , I'm trying to check for the winner
There is a problem inside my if statement.
I want to check if the background of the button changed.
public void CheckForWinner(View arg0)
{
    if ( buttons[0].setBackground()== buttons[1].setBackground()
        && buttons[1].setBackground()==buttons[2].setBackground())
     {}
}

The problem is that: buttons[1].setBackground()... gives me an Error.

A:

First, you cannot initialize an array like that 
public Button buttons[] = null;

You should use the array contructor : 
public Button buttons[] = new Button[9];

Secondly, you cannot compare the backgrounds like this.
Construct another array that save the state of the button like :
Integer[] buttonState = new Integer[9];
And then you can say that if the case is empty, buttonState[i] = 0, 1 for X and 2 for O . And in your if condition you compare the states like that :
public void CheckForWinner(View arg0)
    {
    if ( stateButtons[0] == stateButtons[1]
        && stateButtons[1] == stateButtons[2] )
     {
       // Do something
     }
}

