gpt4 book ai didi

java - 添加计时器并卡住应用程序(android studio)

转载 作者:行者123 更新时间:2023-11-30 01:37:02 26 4
gpt4 key购买 nike

我正在 android studio 上写一个测验应用程序,现在,我的目标是为每个错误答案添加一个时间惩罚,意味着,如果用户回答错误,他将不得不等待,比如说 10 秒,直到他能够再次回答,在这 10 秒内,应用程序将卡住,用户将不得不等待。

我想显示剩余时间。

定时器应该插入到这部分代码中:

    butNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioGroup grp = (RadioGroup) findViewById(R.id.radioGroup1);
RadioButton answer = (RadioButton) findViewById(grp.getCheckedRadioButtonId());
Log.d("yourans", currentQ.getANSWER() + " " + answer.getText());
if (currentQ.getANSWER().equals(answer.getText())) {//bad equal to
score++;
Log.d("good answer", "Your score" + score);
}else {
Log.d("bad answer", "Your score" + score);
***//the time should be implemented here***
}
if (qid < 7) {
currentQ = quesList.get(qid);
setQuestionView();
} else {
Intent intent = new Intent(Questionsctivity.this, ResultActivity.class);
Bundle b = new Bundle();
b.putInt("score", score); //Your score
intent.putExtras(b); //Put your score to your next Intent
startActivity(intent);
finish();
}
}
});

谢谢

最佳答案

试试这个:

new Handler().postDelayed(new Runnable() {
public void run() {
// code called after 5 seconds...
}
}, 5 * 1000);

关于java - 添加计时器并卡住应用程序(android studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34988778/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com