【发布时间】:2015-10-05 19:27:28
【问题描述】:
好的,我正在尝试为我正在为一个项目开发的这款井字游戏设计风格。当我按下新游戏时,我想要某种将每个按钮的背景更改为颜色的数组。然后,当用户单击一个按钮在那里移动时,该空间将根据玩家的不同而变为不同的颜色(我有一个 PlayerTurn 标志变量来确定这一点)。我还想根据与该按钮对应的索引来获取 int 数组中的值。如何为每个按钮分配一个数值,以便以后用于索引到我的数组?
这是我目前正在使用的代码。
Button buttons[] = new Button[9];
buttons[0] = (Button) findViewById(R.id.button0);
buttons[1] = (Button) findViewById(R.id.button1);
buttons[2] = (Button) findViewById(R.id.button2);
buttons[3] = (Button) findViewById(R.id.button3);
buttons[4] = (Button) findViewById(R.id.button4);
buttons[5] = (Button) findViewById(R.id.button5);
buttons[6] = (Button) findViewById(R.id.button6);
buttons[7] = (Button) findViewById(R.id.button7);
buttons[8] = (Button) findViewById(R.id.button8);
【问题讨论】: