我如何限制问题,完成并禁用游戏 我是否在一个类别中有100个问题?我只想将其限制为20个问题,然后转到结果并禁用“开始游戏”按钮。
我的100个问题存储在Java Common.class“ .List <>”中。
我有一个“问题”类,其中包含问题和相应的答案。
Common.class:
public class Common {
public static List<Question> questionList = new ArrayList<>();
}
showQuestion方法:
private void showQuestion(final int index) {
if (index < totalQuestion) {
thisQuestion++;
txtQuestionNum.setText(String.format("%d / %d", thisQuestion, totalQuestion));
progressBar.setProgress(100);
progressValue = 0;
question_text.setText(Common.questionList.get(index).getQuestion());
//if question is text we will set image to invisible
btnA.setText(Common.questionList.get(index).getAnswerA());
btnB.setText(Common.questionList.get(index).getAnswerB());
btnC.setText(Common.questionList.get(index).getAnswerC());
btnD.setText(Common.questionList.get(index).getAnswerD());
mCountDown.start();
}
else {
// if it is final question
Intent intent = new Intent(Playing.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();
}
}
Question.class:
public class Question {
private String Question,AnswerA,AnswerB,AnswerC,AnswerD,CorrectAnswer,CategoryId;
public Question() {
}
public Question(String question, String answerA, String answerB, String answerC, String answerD, String correctAnswer, String categoryId) {
Question = question;
AnswerA = answerA;
AnswerB = answerB;
AnswerC = answerC;
AnswerD = answerD;
CorrectAnswer = correctAnswer;
this.CategoryId = categoryId;
}
public String getQuestion() {
return Question;
}
public void setQuestion(String question) {
Question = question;
}
public String getAnswerA() {
return AnswerA;
}
public void setAnswerA(String answerA) {
AnswerA = answerA;
}
public String getAnswerB() {
return AnswerB;
}
public void setAnswerB(String answerB) {
AnswerB = answerB;
}
public String getAnswerC() {
return AnswerC;
}
public void setAnswerC(String answerC) {
AnswerC = answerC;
}
public String getAnswerD() {
return AnswerD;
}
public void setAnswerD(String answerD) {
AnswerD = answerD;
}
public String getCorrectAnswer() {
return CorrectAnswer;
}
public void setCorrectAnswer(String correctAnswer) {
CorrectAnswer = correctAnswer;
}
public String getCategoryId() {
return CategoryId;
}
public void setCategoryId(String categoryId) {
this.CategoryId = categoryId;
}
}
答案 0 :(得分:0)
当列表中有20个问题答案时,关闭与firebase的数据检索连接,然后相应地更新UI。
这样的事情。
if(listWithQuestionsAndAnswers.size > 20)
{
// stop thats enough, Update UI , disable game.
} else {
// carry on.
}
此检查应采用从Firebase为您提供数据快照的方法。