Код
private void updateQuestion() {
mDatabaseReference.child("Users").child(RecieversId).child("Quiz").child("Question" + mQuestionNumber).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String question = dataSnapshot.child("Question").getValue().toString();
answer = dataSnapshot.child("Answer").getValue().toString();
option1 = dataSnapshot.child("Option1").getValue().toString();
option2 = dataSnapshot.child("Option2").getValue().toString();
option3 = dataSnapshot.child("Option3").getValue().toString();
option4 = dataSnapshot.child("Option4").getValue().toString();
que.setText(question);
opt1.setText(option1);
opt2.setText(option2);
opt3.setText(option3);
opt4.setText(option4);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
opt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (option1.equals(answer)) {
opt1.setBackgroundColor(Color.GREEN);
mScore++;
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt1.setBackgroundColor(Color.CYAN);
}
}, 1500);
} else
opt1.setBackgroundColor(Color.RED);
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt1.setBackgroundColor(Color.CYAN);
}
}, 1500);
}
});
opt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (option2.equals(answer)) {
opt2.setBackgroundColor(Color.GREEN);
mScore++;
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt2.setBackgroundColor(Color.CYAN);
}
}, 1500);
} else
opt2.setBackgroundColor(Color.RED);
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt2.setBackgroundColor(Color.CYAN);
}
}, 1500);
}
});
opt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (option3.equals(answer)) {
opt3.setBackgroundColor(Color.GREEN);
mScore++;
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt3.setBackgroundColor(Color.CYAN);
}
}, 1500);
} else
opt3.setBackgroundColor(Color.RED);
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt3.setBackgroundColor(Color.CYAN);
}
}, 1500);
}
});
opt4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (option4.equals(answer)) {
opt4.setBackgroundColor(Color.GREEN);
mScore++;
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt4.setBackgroundColor(Color.CYAN);
}
}, 1500);
} else
opt4.setBackgroundColor(Color.RED);
sco.setText("Score : " + mScore);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mQuestionNumber++;
qn.setText("Question : " + mQuestionNumber);
updateQuestion();
opt4.setBackgroundColor(Color.CYAN);
}
}, 1500);
}
});
}
}
Это ведет себя довольно странно.Когда я получаю первый вопрос и выбираю неправильный ответ, он без проблем переходит к следующему вопросу.Но когда я выбираю правильный ответ, он пропускает следующий вопрос и переходит к вопросу после этого.Например, если я выбираю правильный ответ в вопросе 2, он пропускает вопрос 3 и показывает вопрос 4. Это довольно странно, и я не могу понять, где я ошибся.
Я уверен, что какая-то ошибкав моем заявлении, но не в состоянии понять, что это такое.