我的问题看起来很简单,所以希望我能很快找到答案。
为了总结我的代码,我生成了一个介于1 & 2之间的随机数。根据随机数,我有一个包含easy1
或easy2
("easy" + randomNum
)的字符串questionName
。我想打印questionName
的内容,但不是字符串,请获取数组easy1[0]
或easy2[0]
。str作为数组名称的内容
public void generateQuestion() {
int min = 1;
int max = 2;
Random r = new Random();
int questionToBeSelected = r.nextInt(max - min + 1) + min;
System.out.println(questionToBeSelected);
String questionName = "easy" + questionToBeSelected;
String[] easy1 = {
"In The Phantom Menace, who are the first two characters on screen?", //Question, obviously
"3", //The array child that is correct
"Padme and Annie", //Answer 1
"Obi-Wan and Qui-Gon Jinn", //Answer 2
"Jar Jar Binks", //Answer 3
"Annie and Obi-Wan" //Answer 4
};
String[] easy2 = {
"Sample question",
"2",
"Sample answer",
"Sample answer",
"Sample answer",
"Sample answer",
};
System.out.println(easy1[0]);
TextView questionPlaceholder = (TextView) findViewById(R.id.game_question);
questionPlaceholder.setText(questionName[0]); // <-------- Problem :(
String alreadyPlayedQuestions;
String questionNumber;
}
感谢
感谢您的回答!当我回家时我会看看它。 –