我正在做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; }
答案 0 :(得分:0)
我无法完全按照此处的内容进行操作,但您可以遍历options
,直到文本等于tTQuestion.GetOptions().get(tTQuestion.GetAnswer() - 1)
(这似乎是您获得正确答案的方式)然后设置View
的背景颜色为绿色。