Android问答应用程序倒计时
下面给出了我的代码,每个问题都有一个问题,即当倒计时结束时跳转到下一个问题,倒计时再次开始,我希望当倒计时结束时,它应该跳转到结果页..即使跳转到下一个问题,倒计时也不应该停止Android问答应用程序倒计时,android,android-studio,countdown,Android,Android Studio,Countdown,下面给出了我的代码,每个问题都有一个问题,即当倒计时结束时跳转到下一个问题,倒计时再次开始,我希望当倒计时结束时,它应该跳转到结果页..即使跳转到下一个问题,倒计时也不应该停止 @Override protected void onResume() { super.onResume(); questionPlay = db.getRuleQuestionMode(mode); totalQuestion = questionPlay.size(); mCou
@Override
protected void onResume()
{
super.onResume();
questionPlay = db.getRuleQuestionMode(mode);
totalQuestion = questionPlay.size();
mCountDown = new CountDownTimer(TIMEOUT, INTERVAL) {
@Override
public void onTick(long millisUntilFinished) {
progressBar.setProgress(progressValue);
progressValue++;
}
@Override
public void onFinish() {
mCountDown.cancel();
}
};
showQuestion(index);
db.close();
}
private void showQuestion(final int index) {
if (index < totalQuestion) {
thisQuestion++;
txtQuestion.setText(String.format("%d/%d", thisQuestion, totalQuestion));
progressBar.setProgress(0);
progressValue = 0;
txtView1.setText(questionPlay.get(index).getQus());
btnA.setText(questionPlay.get(index).getAnswerA());
btnB.setText(questionPlay.get(index).getAnswerB());
btnC.setText(questionPlay.get(index).getAnswerC());
btnD.setText(questionPlay.get(index).getAnswerD());
mCountDown.start();
Button btnca =(Button) findViewById(R.id.btnca);
btnca.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StyleableToast st= new StyleableToast(getApplicationContext(),questionPlay.get(index).getCorrectAnswer(), Toast.LENGTH_SHORT);
st.setBackgroundColor(Color.RED);
st.setTextColor(Color.WHITE);
st.setCornerRadius(3);
st.show();
score-=10;
}
});
} else {
Intent intent = new Intent(this, Done.class);
Bundle dataSend = new Bundle();
dataSend.putInt("SCORE", score);
dataSend.putInt("TOTAL", totalQuestion);
dataSend.putInt("CORRECT", correctAnswer);
intent.putExtras(dataSend);
startActivity(intent);
finish();
}
}
@Override
public void onClick(View v) {
mCountDown.cancel();
if (index < totalQuestion) {
Button clickedButton = (Button) v;
if (clickedButton.getText().equals(questionPlay.get(index).getCorrectAnswer())) {
score += 10; // increase score
correctAnswer++; //increase correct answer
showQuestion(++index);
} else {
vibrator.vibrate(50);
showQuestion(++index); // If choose right , just go to next question
}
txtScore.setText(String.format("%d", score));
//clickedButton.setBackgroundColor(Color.YELLOW);;
}
}
@Override
public void onStop() {
if(mCountDown != null)
mCountDown.cancel();
super.onStop();
}
@覆盖
受保护的void onResume()
{
super.onResume();
questionPlay=db.getRuleQuestionMode(模式);
totalQuestion=questionPlay.size();
mCountDown=新的倒计时(超时、间隔){
@凌驾
公共void onTick(长毫秒未完成){
progressBar.setProgress(progressValue);
progressValue++;
}
@凌驾
公共无效onFinish(){
mCountDown.cancel();
}
};
显示问题(索引);
db.close();
}
私有void showQuestion(最终整数索引){
如果(索引<总问题){
这个问题++;
setText(String.format(“%d/%d”,thisQuestion,totalQuestion));
progressBar.setProgress(0);
progressValue=0;
setText(questionPlay.get(index.getQus());
setText(questionPlay.get(index.getAnswerA());
btnB.setText(questionPlay.get(index.getAnswerB());
setText(questionPlay.get(index.getAnswerC());
setText(questionPlay.get(index.getAnswerD());
mCountDown.start();
按钮btnca=(按钮)findViewById(R.id.btnca);
btnca.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
StyleableToast st=newstyleabletoast(getApplicationContext(),questionPlay.get(index.getCorrectAnswer(),Toast.LENGTH\u SHORT);
st.setBackgroundColor(红色);
st.setTextColor(颜色为白色);
圣塞特角半径(3);
圣秀();
得分-=10分;
}
});
}否则{
Intent Intent=新的Intent(这个,Done.class);
Bundle dataSend=新Bundle();
dataSend.putInt(“分数”,分数);
dataSend.putInt(“总计”,总计问题);
dataSend.putInt(“正确”,回答正确);
意向。额外支出(数据结束);
星触觉(意向);
完成();
}
}
@凌驾
公共void onClick(视图v){
mCountDown.cancel();
如果(索引<总问题){
按钮点击按钮=(按钮)v;
if(clickedButton.getText().equals(questionPlay.get(index.getCorrectAnswer())){
分数+=10;//增加分数
correctAnswer++;//增加正确答案
showQuestion(++索引);
}否则{
振动器。振动(50);
showQuestion(++索引);//如果选择正确,请转到下一个问题
}
setText(String.format(“%d”,score));
//单击按钮。设置背景颜色(颜色。黄色);;
}
}
@凌驾
公共void onStop(){
if(mCountDown!=null)
mCountDown.cancel();
super.onStop();
}
删除mCountDown.start()在showQuestion
方法中选择code>
在你的onFinish
方法中,从那里调用你的结果页面我想这就是你要寻找的:是的,它帮助了我,但倒计时的工作方式与我预期的相同,但不是进度条,所以如果进度条在一个问题的末尾有一个值5,当下一个问题开始时,进度条将再次有5个?我应该如何处理进度条,以便在我转到下一个问题时它应该继续?我看到您正在调用progressBar.setProgress(0)
在您的showQuestion
方法中,您在显示下一个问题时为什么将进度设置为0?好的,谢谢您,先生,我知道我犯了一个愚蠢的错误。很高兴为您提供帮助。作为社区的新成员,当你收到问题的答案时,你应该将其标记为已解决