Android 在多项选择应用程序中显示正确答案

Android 在多项选择应用程序中显示正确答案,android,Android,我正在做一个有4个选项的多选应用程序。我下载了一段代码。但是,如果用户的答案是错误的,那么如何提示用户正确的答案呢。正确答案是绿色的。错误的答案是红色 optionOne.setOnClickListener(this); //On First Option selection optionTwo.setOnClickListener(this); //On Second Option selection optionThree.setOnClickLis

我正在做一个有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>

问题:
什么是。。。。
选择权
选择1
选择2
选择3
选择4
答复
2.
这是我的另一个代码

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; }
公共问题(){
IsthisQuestion=false;
答案=-1;
回答=”;
}
公共字符串GetQuestion()
{返回this.question;}
公共无效设置问题(字符串_问题)
{this.question=_question;}
公共阵列列表GetOptions()
{返回this.options;}
公共无效设置选项(ArrayList\u选项)
{this.options=_options;}
public int GetAnswer()
{返回this.answer;}
公共无效设置应答(int\U应答)
{this.answer=_answer;}

我很难准确地理解这里的内容,但是您可以循环查看您的
选项
,直到文本等于
tTQuestion.GetOptions().get(tTQuestion.GetAnswer()-1)
(这似乎就是您获得正确答案的方式),然后将
视图的背景色设置为绿色

你需要更好地描述你想要什么,准确地描述你的问题是什么。“我需要在这里插入一些东西…”没有告诉我们任何事情。您想如何显示正确答案(
TextView
Toast
Alert
…)@codeMagic如果用户答案不正确,我想获取当前正确答案的位置并将其背景改为绿色(同时显示)。我想代码必须插入else语句中。谢谢。代码已经在运行了。以下是当前的情况。如果我在第一次、第二次或第三次尝试时选择了错误答案,则在我最终得到正确答案之前,所有错误答案的背景都将变为红色。我想做的是“如果用户第一次尝试时不正确,正确的答案也会同时显示为绿色”。不再第二次或第三次尝试。