我的問題看起來很簡單,所以希望我能很快找到答案。
爲了總結我的代碼,我生成了一個介於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;
}
感謝
感謝您的回答!當我回家時我會看看它。 –