Reputation: 5
I'm doing sort of questionnaire that contains 10 questions. My issue is that I can run the questions all the way until the 9th question whereby when I answer it, it skips the 10th question and goes straight to the next activity. I'm still new to this.
private void updateQuestion(){
question.setText(surveyQuestions.getQuestion(sSurveyQuestion));
btn1.setText(surveyQuestions.getChoice1(sSurveyQuestion));
btn2.setText(surveyQuestions.getChoice2(sSurveyQuestion));
btn3.setText(surveyQuestions.getChoice3(sSurveyQuestion));
btn4.setText(surveyQuestions.getChoice4(sSurveyQuestion));
btn5.setText(surveyQuestions.getChoice5(sSurveyQuestion));
sAnswer = surveyQuestions.getAnswer(sSurveyQuestion);
sSurveyQuestion++;
questloop();
}
This is the code that shows the questions and the choices.
And here is the code for the next activity:
private void questLoop() {
if(sSurveyQuestion == 10) {
btn1.setVisibility(View.INVISIBLE);
btn2.setVisibility(View.INVISIBLE);
btn3.setVisibility(View.INVISIBLE);
btn4.setVisibility(View.INVISIBLE);
btn5.setVisibility(View.INVISIBLE);
btnNext.setVisibility(View.VISIBLE);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nextActivity();
}
});
btnRetake.setVisibility(View.VISIBLE);
btnRetake.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Redo();
}
});
}
}
Basically the plan is that once all 10 question have been answered, the choices buttons would not be visible and the next activity buttons would be visible.
Can anyone help by showing any examples? I still haven't quite gotten the hang of for-loops.
Upvotes: 0
Views: 54
Reputation: 414
That's because from your condition if(sSurveyQuestion == 10)
. So if question is number 10, then it will execute your next activity. To fix that, you must check if all 10 questions are shown by changing to:
private void questLoop() {
if(sSurveyQuestion > 10) {
...
}
}
Upvotes: 2