2

I have an array of buttons in my Android app. I want pressing a button to cause a different button to turn white. I have code like this:

final Button [][] button = new Button[5][3];

for(int i = 0; i < tableRow.length; i++) {
    for(int j = 0; j < button[i].length; j++) {
        button[i][j] = new Button(this);
        button[i][j].getBackground().setColorFilter(new LightingColorFilter(0x00000000, 0xFF000000));
    }
}

button[0][0].setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        button[0][0].getBackground().setColorFilter(new LightingColorFilter(0x00000000, 0x00FFFFFF));
    }
});

This works fine, but it turns button[0][0] white when it is pressed, while I want pressing button[0][0] to turn button[0][1] white. If I change it to this:

button[0][0].setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        button[0][1].getBackground().setColorFilter(new LightingColorFilter(0x00000000, 0x00FFFFFF));
    }
});

nothing happens when I press button[0][0]. Why?

2
  • reload the view after changing color Commented Jan 22, 2012 at 3:07
  • @BillGary How do you reload the view? Commented Jan 22, 2012 at 3:09

1 Answer 1

4
button[0][1].invalidate();

will force the view to get redrawn.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.