java - 限制 Android 测验应用程序中的问题,我的问题列表来自 Firebase 实时数据库
问题描述
如果我在一个类别中有 100 个问题,如何限制问题、完成和禁用游戏?我只想将其限制为 20 个问题,然后转到结果并禁用开始游戏按钮。
我的 100 个问题存储在 Java Common.class ".List<>" 中。
我有一个包含问题和相应答案的“问题”类。
普通类:
public class Common {
public static List<Question> questionList = new ArrayList<>();
}
显示问题方法:
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();
}
}
问题.类:
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;
}
}
解决方案
当列表中有 20 个问题答案时,关闭与 firebase 的数据检索连接,然后相应地更新 UI。
像这样的东西。
if(listWithQuestionsAndAnswers.size > 20)
{
// stop thats enough, Update UI , disable game.
} else {
// carry on.
}
此检查应采用从 firebase 为您提供数据快照的方法。
推荐阅读
- python - Raspberry Pi 内存不足 - 只读 SD 卡 - tmpfs 和覆盖 100% 已使用
- javascript - React/Redux/Thunk 表单数据流
- android - 如果任何 EditText 字段有文本,则启用按钮,但如果全部为空,则禁用
- redis - 无法连接docker容器外的redis集群
- c# - 带有数据库下拉过滤器的组合框
- python-3.x - 如何用另一个列表检查列表中的列表
- python - 我无法使用使用 pandas Dataframes 作为参数的生成器创建 Dataset.from_generator()
- c# - 在asp.net mvc中加载页面时如何从EF的下拉列表中选择特定国家
- c++ - 从 VS 调试器中的全局函数访问全局 std::map 值会使程序崩溃
- reactjs - React-Redux TypeError:无法读取未定义的属性“地图”