Я делаю приложение для викторины, с множеством вопросов в разных главах. Каждая глава, конечно, является массивом.
Но теперь я подошел к тому моменту, когда мне нужно, чтобы одна конкретная глава извлекла ВСЕ вопросы и ответы из ВСЕХ глав. Так что в основном это массив внутри другого массива / ов.
public void shuffleChapterRandomTest() {
shuffledPositionChapterRandomTest = new String[chapterRandomTestQuestions.length];
for (int k = 0; k < shuffledPositionChapterRandomTest.length; k++) {
shuffledPositionChapterRandomTest[k] = String.valueOf(k);
}
Collections.shuffle(Arrays.asList(shuffledPositionChapterRandomTest));
Log.i("TAG", "shuffle: " + shuffledPositionChapterRandomTest[0] + " " + shuffledPositionChapterRandomTest[1]);
}
public static String shuffledPositionChapterRandomTest[];
private String chapterRandomTestQuestions[][] = {
//This are all the chapters being called
Questions,
chapterTwoQuestions,
chapterThreeQuestions,
chapterFourQuestions,
chapterFiveQuestions,
chapterSixQuestions,
chapterSevenQuestions,
chapterEightQuestions,
chapterNineQuestions,
chapterTenQuestions,
chapterElevenQuestions,
chapterTwelveQuestions,
chapter13Questions,
chapter14Questions
};
//This is my get method
public String[] getChapterRandomTestQuestion(String a) {
return chapterRandomTestQuestions[Integer.parseInt(a)];
}
Когда я пытаюсь извлечь строку из «вопросов» как setText для TextView.
private void updateQuestion() {
if (questionnumber < questionBank.getChapterRandomTestLength()) {
storeUserData.setInt(Constants.TOTAL_QUESTION,questionBank.getChapterRandomTestLength());
binding.tvCountQuestion.setText(questionnumber+1+"/"+questionBank.getChapterRandomTestLength());
binding.tvQuestion.setText(questionBank.getChapterRandomTestQuestion(shuffledPositionChapterRandomTest[questionnumber]));
binding.tvAnsOne.setText(questionBank.getChapterRandomTestChoice(shuffledPositionChapterRandomTest[questionnumber], 1));
binding.tvAnsTwo.setText(questionBank.getChapterRandomTestChoice(shuffledPositionChapterRandomTest[questionnumber], 2));
binding.tvAnsTnree.setText(questionBank.getChapterRandomTestChoice(shuffledPositionChapterRandomTest[questionnumber], 3));
answer = questionBank.getChapterRandomTestCorrectAnswer(shuffledPositionChapterRandomTest[questionnumber]);
questionnumber++;
Показывает ошибку:
Обязательно: Java.lang.String
Найдено: Java.lang.String []
Как я могу вывести вопросы и ответы как строки, а не как массивы. Спасибо!