1
我目前有一個測驗應用程序,其中包括一個問題&三個多項選擇。在每10項測驗結束時,該應用程序將顯示所有10項問題的正確答案。下面是我目前實施,以顯示在結果頁面顯示正確答案的結果(對於錯誤回答問題)的測驗應用程序android
public static String getAnswers(List<Question> questions) {
int question = 1;
StringBuffer sb = new StringBuffer();
for (Question q : questions){
sb.append("Q").append(question).append(") ").append(q.getQuestion()).append("? \n");
sb.append("Answer: ").append(q.getAnswer()).append("\n\n");
question ++;
}
return sb.toString();
}
答案的代碼,我有這些對我QuestionActivity.java
private void setQuestions() {
questionCtr++;
txtQNum.setText("Question " + questionCtr + "/10");
String question = Utility.capitalise(currentQ.getQuestion());
TextView qText = (TextView) findViewById(R.id.question);
qText.setText(question);
List<String> answers = currentQ.getQuestionOptions();
TextView option1 = (TextView) findViewById(R.id.answer1);
option1.setText(answers.get(0));
TextView option2 = (TextView) findViewById(R.id.answer2);
option2.setText(answers.get(1));
TextView option3 = (TextView) findViewById(R.id.answer3);
option3.setText(answers.get(2));
radioGroup.clearCheck();
}
public void onClick(View arg0) {
if (!checkAnswer()) return;
if (curQuiz.isGameOver()){
Intent i = new Intent(this, QuizResult.class);
startActivity(i);
finish();
}
else{
currentQ = curQuiz.getNextQuestion();
setQuestions();
}
}
private boolean checkAnswer() {
String answer = getSelectedAnswer();
if (answer==null){
return false;
}
else {
if (currentQ.getAnswer().equalsIgnoreCase(answer))
{
curQuiz.incrementRightAnswers();
}
else{
curQuiz.incrementWrongAnswers();
}
return true;
}
}
private String getSelectedAnswer() {
RadioButton c1 = (RadioButton)findViewById(R.id.answer1);
RadioButton c2 = (RadioButton)findViewById(R.id.answer2);
RadioButton c3 = (RadioButton)findViewById(R.id.answer3);
if (c1.isChecked())
{
return c1.getText().toString();
}
if (c2.isChecked())
{
return c2.getText().toString();
}
if (c3.isChecked())
{
return c3.getText().toString();
}
return null;
}
我想要做的是隻顯示已回答的問題的正確答案錯誤因此它不會顯示不必要的Q &用戶已正確回答的答案。
如果答案不正確,我應該將哪些代碼放入'//檢查這裏?抱歉。真的不知道。我已經把你給出的代碼儘管@nem – 2014-09-22 13:00:21
@KaitlinReyes嗨,我編輯了我的問題,讓事情變得更加清晰 – nem035 2014-09-22 13:59:36
工作得很好!謝謝! @nem – 2014-09-22 14:25:07