android多项选择测验应用程序

android多项选择测验应用程序,android,Android,你好,我是android编程新手,我已经使用array创建了一个android多项选择测验应用程序。问题是,当所有的问题都在最后完成时,我希望一个新的活动出现,并显示计算结果。我将如何以及在哪里为它编写代码Plz帮助 public class QuestionLibrary { private String mQuestions[] = { "which number comes in the following series ? 10 50 250 1250__?__",

你好,我是android编程新手,我已经使用array创建了一个android多项选择测验应用程序。问题是,当所有的问题都在最后完成时,我希望一个新的活动出现,并显示计算结果。我将如何以及在哪里为它编写代码Plz帮助

public class QuestionLibrary {

private String mQuestions[] = {
        "which number comes in the following series ? 10 50 250 1250__?__",
        "Free is to imprison as Forgive is to_____?",
        "My Mother is Sister of your Brother,what relation m i to you?",
        "Spot out the stranger in the following?"
};

private String mChoices[][] = {
        {"1350","6250","6500","1550"},
        {"Accuse","Accept","Condemn","Punish"},
        {"Uncle","Brother","Cousin","Nephew"},
        {"Atheist","Godly","Holy","Pious"}

};
private String mCorrectAnswers[] = {
        "6250",
        "Punish",
        "Cousin",
        "Atheist"
};
public String getQuestion(int a) {
    String question = mQuestions[a];
    return question;
}
public String getChoice1(int a) {
    String choice0 = mChoices[a][0];
    return choice0;
}
public String getChoice2(int a) {
    String choice1 = mChoices[a][1];
    return choice1;
}
public String getChoice3(int a) {
    String choice2 = mChoices[a][2];
    return choice2;
}
public String getChoice4(int a) {
    String choice3 = mChoices[a][3];
    return choice3;
}
public String getCorrectAnswer(int a) {
    String answer = mCorrectAnswers[a];
    return answer;
}
这里是主要活动

mScoreView = (TextView) findViewById(R.id.score);
    mQuestionView = (TextView) findViewById(R.id.question);
    mButtonChoice1 = (Button) findViewById(R.id.choice1);
    mButtonChoice2 = (Button) findViewById(R.id.choice2);
    mButtonChoice3 = (Button) findViewById(R.id.choice3);
    mButtonChoice4 = (Button) findViewById(R.id.choice4);

    updateQuestion();

    mButtonChoice1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(mButtonChoice1.getText()== mAnswer)
            {

                mScore+=1;
                updateScore(mScore);
                updateQuestion();
                Toast.makeText(MainActivity.this,"Correct",Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(MainActivity.this,"Wrong",Toast.LENGTH_SHORT).show();

                updateQuestion();
            }
        }
    });
    mButtonChoice2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(mButtonChoice2.getText()== mAnswer)
            {

                mScore+=1;
                updateScore(mScore);
                updateQuestion();
                Toast.makeText(MainActivity.this,"Correct",Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(MainActivity.this,"Wrong",Toast.LENGTH_SHORT).show();

                updateQuestion();
            }
        }
    });
    mButtonChoice3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(mButtonChoice3.getText()== mAnswer)
            {

                mScore+=1;
                updateScore(mScore);
                updateQuestion();
                Toast.makeText(MainActivity.this,"Correct",Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(MainActivity.this,"Wrong",Toast.LENGTH_SHORT).show();

                updateQuestion();
            }
        }
    });
    mButtonChoice4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(mButtonChoice4.getText()== mAnswer)
            {

                mScore+=1;
                updateScore(mScore);
                updateQuestion();
                Toast.makeText(MainActivity.this,"Correct",Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(MainActivity.this,"Wrong",Toast.LENGTH_SHORT).show();

                updateQuestion();
            }
        }
    });
}
private void updateQuestion()
{
    mQuestionView.setText(questionLibrary.getQuestion(mQuestionNumber));
    mButtonChoice1.setText(questionLibrary.getChoice1(mQuestionNumber));
    mButtonChoice2.setText(questionLibrary.getChoice2(mQuestionNumber));
    mButtonChoice3.setText(questionLibrary.getChoice3(mQuestionNumber));
    mButtonChoice4.setText(questionLibrary.getChoice4(mQuestionNumber));
    mAnswer = questionLibrary.getCorrectAnswer(mQuestionNumber);
    mQuestionNumber++;
}
private void updateScore(int point)
{
    mScoreView.setText(""+mScore);
}

在updateQuestion方法中编写以下代码

if(mQuestionNumber>3)
{
Intent resultIntent = new Intent (this, ResultActivity.class);
resultIntent.putExtra('SCORE',mScore);
startActivity(resultIntent);
}

在结果活动中,获取额外值并通过文本视图显示它

检查此项嘿,我有类似的应用程序,但获取此错误可帮助我解决:java.lang.ArrayIndexOutOfBoundsException:length=4;指数=4。