抱歉,下面的代码看起来如此笨拙。综上所述,我正在制作一个问答游戏,用户可以选择问题的 4 种难度。例如,如果用户选择复选框 1 和 3,则以下代码旨在将 string.xml 中的字符串数组存储到 String[] NUM_ALL_QuestionNames 中。
//same for checkbox1,2,3, so here not duplicate //
if (checkbox4=="yes")
{
NUM_EXP_QuestionNames = getResources().getStringArray(R.array.Num_Q_Expert_List);
NUM_EXP_AnswerNames = getResources().getStringArray(R.array.Num_A_Expert_List);
QuestionImport= 0;
QuestionImport = NUM_EXP_QuestionNames.length;
int i =0;
while (i<QuestionImport)
{
String Q_toimport = NUM_EXP_QuestionNames[i];
String A_toimport = NUM_EXP_AnswerNames[i];
NUM_ALL_QuestionNames.add(Q_toimport);
NUM_ALL_AnswerNames.add(A_toimport);
++i;
}
};
NUM_ALLL_QuestionNames = new String[NUM_ALL_QuestionNames.size()]; //convert ArrayList<String> to String[]
NUM_ALLL_AnswerNames = new String[NUM_ALL_AnswerNames.size()]; //convert ArrayList<String> to String[]
最后 NUM_ALL_Questionnames 将从 ArrayList NUM_ALLL_QuestionNames 转换回 String[] 以供进一步处理。
string.xml 中的文件应该没有问题,因为当我尝试如下设置(直接从 string.xml 中提取)时,应用程序运行良好:
NUM_ALLL_QuestionNames = getResources().getStringArray(R.array.Num_Q_Simple_List);
NUM_ALLL_AnswerNames = getResources().getStringArray(R.array.Num_A_Simple_List);
问题:
现在它是来自 string.xml 的 String[] 格式的数据,然后它被添加到 List 中,这个 List 最后转换回 String[]。是否有任何修改不需要这种转换。如果 string.xml 可以直接到 String[] 就更好了
当继续执行应用程序时,logcat 不会显示任何错误。但是,模拟器保持黑屏。为什么会这样?代码是否存在无限循环?
非常感谢!