I made a layout with some views and I need to force redraw it, because I found that invalidate isn't redrawing instantly if I use Thread.sleep()
.
So, I also found that i can use SurfaceHolder to achieve this, but I don't know how to use it.
If someone can explain me how to use surfaceholder with layout or just another way to force redraw a specific view from the layout.
So, I have some buttons that I change their color programmatically, but the new color is not displayed. Here is how the color is changed:
while(array[k] < 4) {
while(!running) {
Thread.sleep(100);
}
array[k] ++;
Position(k);
if(Validation(k)) {
buttons[solution[k].y][solution[k].x].setBackgroundColor(getResources().getColor(R.color.moving));
buttons[solution[k].y][solution[k].x].forceLayout();
if(solution[k].x == 0 || solution[k].x == width - 1 || solution[k].y == 0 || solution[k].y == height - 1) {
DisplaySolution(k);
Thread.sleep(300);
ResetMatrix();
} else {
Bkt(k + 1);
}
} else {
buttons[solution[k].y][solution[k].x].setBackgroundColor(getResources().getColor(R.color.unpressedEmpty));
}
}
I did console log between these and it is executing very well, except that the new color(named "moving") isn't displayed.
The ResetMatrix() function resets the colors, but that shouldn't affect this.
I also tried with buttons[solution[k].y][solution[k].x].invalidate();
, but didn't work.