Textview无法在strings.xml中打印下一个数组

时间:2016-12-05 17:15:03

标签: android

我需要一些帮助。我试图制作一个测验应用程序,当我点击下一个按钮时,文本视图中的问题会发生变化,但当我单击下一个按钮时,我的文本视图将不会更改为string.xml中数组上的下一个字符串

question.java

我的onNextClick方法将我的问题更改为下一个。

 public void onNextClick(View view) {
    if (done) {
        String[] questions = getResources().getStringArray(R.array.Questions);
        if (QuestionNo < (questions.length - 1)) {
            QuestionNo = QuestionNo++;
            TextView t = (TextView) findViewById(R.id.question);
            t.setText(questions[QuestionNo]);


            findViewById(R.id.tickcross).setVisibility(View.INVISIBLE);
            findViewById(R.id.correctornot).setVisibility(View.INVISIBLE);
            findViewById(R.id.nextbutton).setVisibility(View.INVISIBLE);
            EditText et = (EditText) findViewById(R.id.answer);
            et.setText("");

            done = false;
        }
    }
}

我的onAnswerClick方法

public void onAnswerClick(View view) {
    if (done == false) {
        String answer = ((EditText) findViewById(R.id.answer)).getText().toString();
        String[] answers = getResources().getStringArray(R.array.Answers);
        String correctanswer = answers[QuestionNo];
        //gets the answer and correct answer from the edit text and strings.xml respectively
        correctanswer = correctanswer.toUpperCase();
        answer = answer.toUpperCase();
        //makes sure that the strings are lower case


        if (answer.equals(correctanswer)) {
            TextView t = (TextView) findViewById(R.id.correctornot);
            t.setText("CORRECT!");
            MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.right);
            mp.start();
            ImageView i = (ImageView) findViewById(R.id.tickcross);
            i.setImageDrawable(getDrawable(R.drawable.weirdtick));
            answersubmitted();

        } else {
            TextView t = (TextView) findViewById(R.id.correctornot);
            t.setText("CORRECT ANSWER: " + correctanswer);
            MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.wrong);
            mp.start();
            ImageView i = (ImageView) findViewById(R.id.tickcross);
            i.setImageDrawable(getDrawable(R.drawable.weirdcross));
            answersubmitted();
        }
        done = true;
    }
}

我的string.xml

  <string-array name="Questions">
    <item>What is the letter A in the phonetic alphabet? LOLOL</item>
    <item>What is the letter B in the phonetic alphabet?</item>
    <item>What is the letter C in the phonetic alphabet?</item>
</string-array>

<string-array name="Answers">
    <item>alpha</item>
    <item>bravo</item>
    <item>charlie</item>
</string-array>

<string-array name="Hints">
    <item>A tough, domineering bloke</item>
    <item>Well done!</item>
    <item>Snoopy\'s mate</item>
</string-array>
希望你们能帮助我纠正或指出我的错误。谢谢

0 个答案:

没有答案