我正在做一个有 4 个选择的多项选择应用程序。如果用户(同时)按下了错误的答案,如何提示用户正确答案。这里是一个代码示例。
//Question/Answer options listener
optionOne.setOnClickListener(this); //On First Option selection
optionTwo.setOnClickListener(this); //On Second Option selection
optionThree.setOnClickListener(this); //On Third Option selection
optionFour.setOnClickListener(this); //On Forth Option selection
skip.setOnClickListener(this); //On Question Skip
pause.setOnClickListener(this); //On Game Pause
end.setOnClickListener(this); //On Game End
}
public void onClick(View v) {
if(v.getId() == optionOne.getId()){
onOptionSelected(optionOne.getText().toString());
}else if(v.getId() == optionTwo.getId()){
onOptionSelected(optionTwo.getText().toString());
}else if(v.getId() == optionThree.getId()){
onOptionSelected(optionThree.getText().toString());
}else if(v.getId() == optionFour.getId()){
onOptionSelected(optionFour.getText().toString());
}else if(v.getId() == pause.getId()){ //True when Game is Paused
//When an option of a question is selected
private void onOptionSelected(String option){
if(!isGamePaused && !isGameEnded) { //true when game is being played
ATriviaQuestion tTQuestion = myListOfTriviaQuestions.get(currentQuestionNumber);
if(option.equals(tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1))) {
correct += 1;
remainingTime = mySecondsPassed;
totalPoints += remainingTime * pointsPerRemainingSecond;
totalPoints += pointsPerCorrectAnswer;
}
else{
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
}
我需要在这部分插入一些东西来显示正确的答案。
else{
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
selectedOptionTxt.setBackgroundColor(Color.RED);
Here is my .plist
<question>
<key>Question</key>
<string>What is the ....</string>
<key>Options</key>
<array>
<string>option 1</string>
<string>option 2</string>
<string>option 3</string>
<string>option 4</string>
</array>
<key>Answer</key>
<integer>2</integer>
</question>
这是另一个代码
public ATriviaQuestion(){
isThisQuestionAsked = false;
answer = -1;
answered = "";
}
public String GetQuestion()
{ return this.question; }
public void SetQuestion(String _question)
{ this.question=_question; }
public ArrayList<String> GetOptions()
{ return this.options; }
public void SetOptions(ArrayList<String> _options)
{ this.options = _options; }
public int GetAnswer()
{ return this.answer; }
public void SetAnswer(int _answer)
{ this.answer = _answer; }