我正在做一個(gè)測(cè)驗(yàn)應(yīng)用程序,在不同的章節(jié)中有很多問題。當(dāng)然每一章都是一個(gè)數(shù)組。但是現(xiàn)在,我已經(jīng)到了需要一個(gè)特定章節(jié)來從所有章節(jié)中提取所有問題和答案的地步。所以基本上它是另一個(gè)數(shù)組中的一個(gè)數(shù)組。 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 methodpublic String[] getChapterRandomTestQuestion(String a) { return chapterRandomTestQuestions[Integer.parseInt(a)];}當(dāng)我嘗試從“問題”中提取字符串作為 TextView 的 setText 時(shí)。 private void updateQuestion() { if (questionnumber < questionBank.getChapterRandomTestLength()) { storeUserData.setInt(Constants.TOTAL_QUESTION,questionBank.getChapterRandomTestLength()); binding.tvCountQuestion.setText(questionnumber+1+"/"+questionBank.getChapterRandomTestLength());它顯示一個(gè)錯(cuò)誤:必需:Java.lang.String 找到:Java.lang.String[]如何將問題和答案提取為字符串而不是數(shù)組。謝謝!
如何從字符串?dāng)?shù)組中獲取字符串以便它可以與 SetText 一起使用?安卓工作室
寶慕林4294392
2021-09-03 15:14:14