为什么我的问题和照片没有相同的结果

我正在尝试制作一个 android 问答游戏,它随机化我的问题和图像以帮助回答问题..但是在游戏中尝试 2 次后,随机值不会返回相同的值.. randomNum 是我用来获取的 int随机数.. 我希望两个问题同步..


Random random = new Random();

//get random number between 0 to 9.

int randomNum = random.nextInt(quizArray.size());


//image

imageView.setBackgroundResource(image[randomNum]);

//pick quiz

ArrayList<String> quiz = quizArray.get(randomNum);


//set question and answer

questionLabel.setText(quiz.get(0));

rightAnswer = quiz.get(1);


//remove question


quiz.remove(0);

Collections.shuffle(quiz);


//set Choices

btn1.setText(quiz.get(0));

btn2.setText(quiz.get(1));

btn3.setText(quiz.get(2));

btn4.setText(quiz.get(3));


//remove quiz from quizArray

quizArray.remove(randomNum);

}


ITMISS
浏览 155回答 3
3回答

子衿沉夜

当您quizArray使用此&nbsp;删除测验时,您quizArray.remove(randomNum);还需要从image[]表格中删除相关图像,我建议您使用List图像而不是table这样,您也可以image.remove(randomNum);在之后使用&nbsp;quizArray.remove(randomNum);

MM们

你为什么不创建一个Question与域类questionString,answerString和image。然后您可以创建一个Question对象列表,只需Question从列表中删除 即可删除所有关联的问题数据。class Question {&nbsp; &nbsp; public final String questionString;&nbsp; &nbsp; public final String answerString;&nbsp; &nbsp; public final byte[] image;&nbsp; &nbsp; public Question(String question, String answer, byte[] image) {&nbsp; &nbsp; &nbsp; &nbsp; questionString = question;&nbsp; &nbsp; &nbsp; &nbsp; answerString = answer;&nbsp; &nbsp; &nbsp; &nbsp; this.image = image;&nbsp; &nbsp; }}...List<Question> questions = new ArrayList<>();//Populate questions however//I would suggest reading the questions from an XML file//Instead of static array declarations for ease of use in the futureSystem.out.println(questions);questions.remove(0);System.out.println(questions);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java