Android的答案列表不会移动到下一个答案列表



我一直有这个问题在按钮显示4个答案。当播放类运行时,8、9、3、1确实会出现,但在按下按钮后,它不会移动到下一个答案列表(17、20、15、14等)…

Java

public class play extends Activity  {
private Question currentQuestion;
private int currentQuestionIndex;
private ArrayList<Button> questionButton;
private TextView questionstextview;
private TextView questionnumber;
private TextView playerfeedback;
public static TextView displayscore;
public static int score;
private List<Question> QuestionList;
private int answerchoice; 
public static int totalanswer;
public static int correctanswer;
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play);
        Log.i("playclass", "this is play class running");
        questionButton = new ArrayList<Button>();       
        questionButton.add((Button) findViewById (R.id.answerbutton1));
        questionButton.add((Button) findViewById (R.id.answerbutton2));
        questionButton.add((Button) findViewById (R.id.answerbutton3));
        questionButton.add((Button) findViewById (R.id.answerbutton4));
        currentQuestion = null;
        currentQuestionIndex = 0;
        QuestionList = new ArrayList<Question>();
        ArrayList <String> answer = new ArrayList<String>();
        answer.add("8");
        answer.add("9");
        answer.add("3");
        answer.add("1");
        QuestionList.add(new Question("what is 4+4", answer, 0));
        answer.add("17");
        answer.add("20");
        answer.add("15");
        answer.add("14");
        QuestionList.add(new Question("what is 7+8?", answer, 3));
        answer.add("20");
        answer.add("30");
        answer.add("19");
        answer.add("34");
        QuestionList.add(new Question("what is 10+10?", answer, 0));
        answer.add("12");
        answer.add("11");
        answer.add("13");
        answer.add("14");
        QuestionList.add(new Question("what is 6+6?", answer, 0));
        answer.add("6");
        answer.add("5");
        answer.add("4");
        answer.add("7");
        QuestionList.add(new Question("what is 4+3?", answer, 3));
        answer.add("7");
        answer.add("9");
        answer.add("10");
        answer.add("11");
        QuestionList.add(new Question("what is 3+7?", answer, 2));
        questionstextview = (TextView) findViewById (R.id.questionstextview);           
        questionnumber = (TextView) findViewById (R.id.questionnumber);        
        displayscore = (TextView) findViewById (R.id.displayscore);
        StartTrivia();
    }
public void ButtonPress (View answerButton){
    MediaPlayer soundfx = MediaPlayer.create(getApplicationContext(), R.raw.click);
    soundfx.start();
    for (int i=0; i< questionButton.size(); i++)
    {   

        if (questionButton.get(i) ==answerButton)
        {   
         if (i==currentQuestion.getAnswerIndex())
          { 
             score=+5;
             totalanswer++;
             correctanswer++;
            displayscore.setText(Integer.toString(score));
            Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_SHORT).show();
        }
        else{
            totalanswer++;
            Toast.makeText(getApplicationContext(), "Incorrect!", Toast.LENGTH_SHORT).show();
             Log.i("playclass", "after incorrect toast");
        }
            currentQuestionIndex++;

             Log.i("playclass", "after currentQuestionIndex++; ");
            if (currentQuestionIndex < QuestionList.size()){
                Log.i("playclass", "after currentQuestionIndex < QuestionList.size() ");
                StartTrivia();
                Log.i("playclass", "after StartTrivia in if statement ");
            }
            else{
                Intent result = new Intent (this, finalscreen.class);
                startActivity(result);
                Log.i("playclass", "after IntentResult ");
            }
            break;
         }
    }   
}
public void StartTrivia(){
    Log.i("playclass", "running StartTrivia() " + currentQuestionIndex); 
    currentQuestion = QuestionList.get(currentQuestionIndex); 
    questionstextview.setText(currentQuestion.getquestion());
    questionnumber.setText(Integer.toString(currentQuestionIndex+1));
    for (int i = 0; i < questionButton.size(); i++)
     { 
         String ans = currentQuestion.getanswer().get(i); 
         questionButton.get(i).setText(ans);
     }
    }

}

LogCat

08-13 14:55:02.341: I/ActivityManager(73): Starting: Intent {cmp=com.example.quizgame/。播放}从pid 387
[08 . 13] 14:55:02.651:我/playclass(387):这是playclass在运行
08-13 14:55:02.671: I/playclass(387): running StartTrivia() 0
08-13 14:55:03.422:我/ActivityManager(73):显示com.example.quizgame/。玩:+ 1 s2ms
08:13 14:55:05.634: D/dalvikvm(387): GC_CONCURRENT释放92K, 3%释放9024K/9287K,暂停9ms+5ms
08-13 14:55:05.711: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:05.851: I/playclass(387): after currentquestionindex++;
08-13 14:55:05.851:我/playclass(387): after currentQuestionIndex
08-13 14:55:05.861: I/playclass(387): running StartTrivia() 1
08-13 14:55:05.861: I/playclass(387): after StartTrivia在if语句
08-13 14:55:08.712: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:08.745: I/playclass(387): after incorrect toast
08-13 14:55:08.745:我/playclass(387): after currentquestionindex++;
08-13 14:55:08.752:我/playclass(387): after currentQuestionIndex
08-13 14:55:08.752: I/playclass(387): running StartTrivia() 2
08-13 14:55:08.775: I/playclass(387): after StartTrivia in if语句
08-13 14:55:09.182: I/dalvikvm(73): Jit: resizing JitTable from 1024 to 2048
08-13 14:55:10.102: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:10.162:我/playclass(387): after currentquestionindex++;
08-13 14:55:10.162:我/playclass(387): after currentQuestionIndex
08-13 14:55:10.172: I/playclass(387): running StartTrivia() 3
08-13 14:55:10.231: I/playclass(387): after StartTrivia in if语句
08:13 14:55:10.388: W/AudioFlinger(32):写阻塞75 msecs, 1个写延迟,线程0xff38
08-13 14:55:11.911: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:12.011: I/playclass(387): after currentquestionindex++;
08-13 14:55:12.011:我/playclass(387): after currentQuestionIndex
08-13 14:55:12.011: I/playclass(387): running StartTrivia() 4
08-13 14:55:12.011: I/playclass(387): after StartTrivia在if语句
08-13 14:55:14.011: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:14.072: I/playclass(387): after incorrect toast
08-13 14:55:14.072: I/playclass(387): after currentquestionindex++;
08-13 14:55:14.092:我/playclass(387): after currentQuestionIndex
08-13 14:55:14.092: I/playclass(387): running StartTrivia() 5
08-13 14:55:14.111: I/playclass(387): after StartTrivia in if语句
08-13 14:55:17.691: D/AudioSink(32): bufferCount(4)太小,增加到12
08-13 14:55:17.761: I/playclass(387): after incorrect toast
08-13 14:55:17.761: I/playclass(387): after currentquestionindex++;
08-13 14:55:17.822:我/ActivityManager(73): Starting: Intent {cmp=com.example.quizgame/。Finalscreen} from pid 387
08-13 14:55:17.876: I/playclass(387): after IntentResult
08:13 14:55:18.112: W/AudioFlinger(32):写阻塞76 msecs, 6个写延迟,线程0xff38
08-13 14:55:18.251:我/finalscreen(387):这是finalscreen类正在运行
08-13 14:55:19.481: I/ActivityManager(73): display com.example.quizgame/。finalscreen: + 1 s582ms

     ArrayList <String> answer = new ArrayList<String>();
    answer.add("8");
    answer.add("9");
    answer.add("3");
    answer.add("1");
    QuestionList.add(new Question("what is 4+4", answer, 0));
    ArrayList <String> answer1 = new ArrayList<String>();
    answer1.add("17");
    answer1.add("20");
    answer1.add("15");
    answer1.add("14");
    QuestionList.add(new Question("what is 7+8?", answer1, 3));
   ArrayList <String> answer2 = new ArrayList<String>();
    answer2.add("20");
    answer2.add("30");
    answer2.add("19");
    answer2.add("34");
    QuestionList.add(new Question("what is 10+10?", answer2, 0));
    ArrayList <String> answer3 = new ArrayList<String>();
    answer3.add("12");
    answer3.add("11");
    answer3.add("13");
    answer3.add("14");
    QuestionList.add(new Question("what is 6+6?", answer3, 0));
    ArrayList <String> answer4 = new ArrayList<String>();
    answer4.add("6");
    answer4.add("5");
    answer4.add("4");
    answer4.add("7");
    QuestionList.add(new Question("what is 4+3?", answer4, 3));
   ArrayList <String> answer5 = new ArrayList<String>();
    answer5.add("7");
    answer5.add("9");
    answer5.add("10");
    answer5.add("11");
    QuestionList.add(new Question("what is 3+7?", answer5, 2));

相关内容

  • 没有找到相关文章

最新更新