主题zufallsXThread = new Thread(){
@Override
public void run() {
while (fail > 3) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
int zufall = (int) (Math.random() * 9) + 1;
if (zufall == 1) {
this.getButton1().setText("x");
} else if (zufall == 2) {
this.getButton2().post("x");
} else if (zufall == 3) {
this.getButton3().setText("x");
} else if (zufall == 4) {
this.getButton4().setText("x");
} else if (zufall == 5) {
this.getButton5().setText("x");
} else if (zufall == 6) {
this.getButton6().setText("x");
} else if (zufall == 7) {
this.getButton7().setText("x");
} else if (zufall == 8) {
this.getButton8().setText("x");
} else if (zufall == 9) {
this.getButton9().setText("x");
}
}
});
}
}
};
答案 0 :(得分:1)
从方法调用中删除this
关键字。
if (zufall == 1) {
getButton1().setText("x");
}
并在run方法中更改所有内容。