我想显示剩余的时间。
计时器应插入代码的这一部分:
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();
}
}
});
感谢
答案 0 :(得分:1)
试试这个:
new Handler().postDelayed(new Runnable() {
public void run() {
// code called after 5 seconds...
}
}, 5 * 1000);
答案 1 :(得分:0)
您可以disable
Click Listeners
和all the listeners
特定时间,然后您可以继续在TextView
中显示剩余时间计时器,当达到10秒时,您可以启用点击监听器。
希望这会有所帮助。
答案 2 :(得分:0)
以下是我的解决方案,它很容易理解。希望它有所帮助。
new CountDownTimer(30000, 1000) {
@Override
public void onFinish() {
mTextField.setText("done!");
// enable your view by butNext.setOnClickListener(listener) or radioGroup.setEnable(true)...
}
@Override
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
// disable your view by butNext.setOnClickListener(null) or radioGroup.setEnable(false)...
}
};