ループを繰り返すたびに GUI を更新しようとしています。同様の質問に対する他の回答を読みましたが、まだ機能しません。以下のコードでは、simulate を呼び出します。これは、必要に応じて GUI コンポーネントを計算および変更するループ呼び出しステップを実行しますが、ループが完全に終了するまで GUI は更新されません。各反復後に更新するにはどうすればよいですか?
public void step(View v) {
for (int i = 0; i < cells.length; i++)
update(i);
count++;
Toast.makeText(getApplicationContext(), count + "", 1000).show();
}
public void simulate(View v) {
while (!pause) {
step(v);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void update(final int i)
{
//This goes through each button and counts the neighbors (this is the
//intensive work
int neighbors = getNeighbors(i);
//With the information provided from the getNeighbors the following if
//statement updates the GUI using the dead and alive method calls.
if (isAlive(cells[i])) {
if (neighbors < 2)
dead(cells[i]);
else if (neighbors > 3)
dead(cells[i]);
}
else {
if (neighbors == 3)
alive(cells[i]);
}
}