根据https://stackoverflow.com/a/22875621/9023855的建议,为什么我的代码没有按预期工作?我的计划是自动点击按钮。
private boolean threadDone = true;
public void setTimer(final boolean shown_answer, final TextToSpeech tts){
final Handler h =new Handler();
Runnable r = new Runnable() {
public void run() {
if (!tts.isSpeak() && threadDone) {
onTtsFinished(shown_answer);
}
h.postDelayed(this, 1000);
}
};
h.postDelayed(r, 1000);
}
public void onTtsFinished(boolean shown_answer) {
threadDone = false;
if(showAnswer && !shown_answer){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
button.performClick();
threadDone = true;
}
}, showDelay);
}
if(nextQuestion && shown_answer){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
button.performClick();
threadDone = true;
}
}, nextDelay);
}
}