Hi I'm new to programming, I know there is probably some easy answer to this but cant quite get there.
So basically I want to know if the background image for two buttons match and if they do disable them (or some other function). Heres my code, for the moment I am focusing on Button1 and Button2.
Look at the end method, I know if wont work but thats what im trying to do. Thanks.
package com.example.pairsgame;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
public final static int Button_Count = 12;
private Button[] Buttons = new Button[Button_Count];
{
Buttons[0] = (Button) findViewById(R.id.Button1);
Buttons[1] = (Button) findViewById(R.id.Button2);
Buttons[2] = (Button) findViewById(R.id.Button3);
Buttons[3] = (Button) findViewById(R.id.Button4);
Buttons[4] = (Button) findViewById(R.id.Button5);
Buttons[5] = (Button) findViewById(R.id.Button6);
Buttons[6] = (Button) findViewById(R.id.Button7);
Buttons[7] = (Button) findViewById(R.id.Button8);
Buttons[8] = (Button) findViewById(R.id.Button9);
Buttons[9] = (Button) findViewById(R.id.Button10);
Buttons[10] = (Button) findViewById(R.id.Button11);
Buttons[11] = (Button) findViewById(R.id.Button12);
Buttons[0].setOnClickListener(this);
Buttons[1].setOnClickListener(this);
Buttons[2].setOnClickListener(this);
Buttons[3].setOnClickListener(this);
Buttons[4].setOnClickListener(this);
Buttons[5].setOnClickListener(this);
Buttons[6].setOnClickListener(this);
Buttons[7].setOnClickListener(this);
Buttons[8].setOnClickListener(this);
Buttons[9].setOnClickListener(this);
Buttons[10].setOnClickListener(this);
Buttons[11].setOnClickListener(this);
}
public static int Background_Total = 8;
public final static int[] Backgrounds = { R.drawable.ic_launcher };
public final static int[] Game_Board = {
0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
@Override
public void onClick(View v) {
for (final int but = 0; but < Button_Count; but++) {
if (v == Buttons[but]) {
new CountDownTimer(1000, 500) {
public void onTick(long millisUntilFinished) {
Buttons[but].setBackgroundResource(Backgrounds[Game_Board[but]]);
}
public void onFinish() {
Buttons[but].setBackgroundResource(android.R.drawable.btn_default);
}
}.start();
if (Game_Board[0] == Game_Board[2])
Buttons[0].setEnabled(false);
Buttons[2].setEnabled(false);
}
}
}
}