我正在做一个有 4 个选择的多项选择应用程序。我已经下载了一个代码。但是如果他的答案是错误答案(同时)如何提示用户正确答案。这是代码示例。正确答案是绿色。错误答案是红色的。
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
public void onClick(View v) {
if(v.getId() == optionOne.getId()){
onOptionSelected(optionOne.getText().toString(), v);
optionOne.setBackgroundColor(Color.RED);
}else if(v.getId() == optionTwo.getId()){
onOptionSelected(optionTwo.getText().toString(), v);
optionTwo.setBackgroundColor(Color.RED);
}else if(v.getId() == optionThree.getId()){
onOptionSelected(optionThree.getText().toString(), v);
optionThree.setBackgroundColor(Color.RED);
}else if(v.getId() == optionFour.getId()){
onOptionSelected(optionFour.getText().toString(), v);
optionFour.setBackgroundColor(Color.RED);
}else if(v.getId() == pause.getId()){ //True when Game is Paused
//When an option of a question is selected
private void onOptionSelected(String option, View v){
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;
v.setBackgroundColor(Color.GREEN);
}
else{
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
}
如果用户答案不正确,我需要在这部分插入代码以在绿色背景中显示正确答案,但我不知道如何。
else{
incorrect += 1;
totalPoints -= pointsPerWrongAnswer;
数据库问题在 .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; }