The game "tic-zeroes". Created 9 buttons, placed in an array to declare and distribute id. I can not figure out how to make sure that after my pressing the button (to enter X), a null appears on another random button. I understand that you need to use Math.random (). Just like ... A simple question, ashamed to ask, please ask a farewell.
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ Button button[]= new Button[9]; Button b1pl,b2pl; private Integer allid[]={ R.id.button1, R.id.button2, R.id.button3, R.id.button4, R.id.button5, R.id.button6, R.id.button7, R.id.button8, R.id.button9}; boolean first= true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b2pl = (Button) findViewById(R.id.b2pl); b2pl.setOnClickListener(this); b1pl = (Button) findViewById(R.id.b1pl); b1pl.setOnClickListener(this); for (int i=0;i<allid.length;i++){ button[i]=findViewById(allid[i]); button[i].setOnClickListener(this); } } @SuppressLint("ResourceAsColor") @Override public void onClick(View view) { Button current = new Button(this); current.setTextSize(24); switch (view.getId()){ case R.id.b1pl: if (first){ current.setTypeface(null,Typeface.BOLD); current.setTextColor(R.color.colorPrimaryDark); current.setText("X"); } else { current.setText("0"); current.setTextColor(R.color.colorPrimaryDark); } first=!first; } } } 