0

I'm designing a tic-tac-toe game.

The layout of the game is a LinearLayout (vertical) which has a button (reset), a TableLayout, and another button (submit). The TableLayout has TableRows, which in turn have Buttons.

The idea of my design is, when you hit submit, it sends the last pressed button (in the TableLayout) to the running game as "user input", and then after every move, the TableLayout updates to reflect the changes (the text changes to reflect which player owns that spot, disables the clickability of the button, and a splash of color because why not).

private void updateButton(Button button, char claimant)
{
    button.setText(claimant == 'X' ? "X" : claimant == 'O' ? "O" : " ");
    button.setTextColor(claimant == 'X' ? 0x500000 : 
                        claimant == 'O' ? 0x332c2c :
                                          button.getCurrentTextColor());
    button.setClickable(claimant == ' ');
}

I have tried with adding these lines at the end of updateButton(), and nothing seems to work:

button.setWillNotDraw(false);
button.bringToFront();
button.invalidate();
button.postinvalidate();

What I need to do is - make Button disabled and make it appear as one.

Sufian
  • 6,405
  • 16
  • 66
  • 120
  • Could you briefly state what do you want to do? Do you want to disable the button (i.e make it not-clickable) or want to update its text or appearance? – Sufian Jun 26 '16 at 01:12
  • 1
    you dont need to invalidate to update button text and color. setText and setTextColor will work. Check if the claimant and the button you are sending are the right ones. – user3215142 Jun 26 '16 at 09:20
  • I want to update its text and appearance (I also want to make it not-clickable, but that part is working properly) – user6513601 Jun 26 '16 at 16:45
  • I ran it through the debugger on Android Studio to check that everything is correct and everything is in proper order – user6513601 Jun 26 '16 at 16:47
  • @user6513601 does [this](http://stackoverflow.com/questions/4384890/how-to-disable-an-android-button) help? – Sufian Jul 03 '16 at 00:11

0 Answers0