Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-复选框和字符串[]_Android_String_Checkbox - Fatal编程技术网

android-复选框和字符串[]

android-复选框和字符串[],android,string,checkbox,Android,String,Checkbox,很抱歉,下面的代码看起来很笨拙。总而言之,我正在做一个问答游戏,用户可以选择问题的4种难度。 例如,如果用户选择复选框1和3,下面的代码旨在将string.xml中的字符串数组存储到string[]NUM_ALL_QuestionNames中 //same for checkbox1,2,3, so here not duplicate // if (checkbox4=="yes") { NUM_EXP_QuestionNames = getRe

很抱歉,下面的代码看起来很笨拙。总而言之,我正在做一个问答游戏,用户可以选择问题的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[]
问题:
  • 现在是string[]格式的string.xml中的数据,然后将其添加到列表中,该列表最后转换回string[]。是否有任何修改不需要此转换。如果string.xml可以直接连接到string[]

  • 继续执行应用程序时,logcat不会显示任何错误。但是,模拟器保持黑屏。为什么会这样?代码是否有无休止的循环


  • 非常感谢

    我不明白为什么checkbox4值是字符串,但是永远不要通过==比较字符串,因为这样可以比较可能指向不同对象的链接。 相反,使用字符串中的equals方法,如下所示 如果(复选框4.equals(“yes”)

    这是错误的:

    NUM_ALLL_QuestionNames = new String[NUM_ALL_QuestionNames.size()]; //convert ArrayList<String> to String[]
    
    假设
    NUM\u ALL\u QuestionNames
    是一个列表


    医生是对的,这种字符串比较在Java中不起作用。

    aouch。java 101:字符串与等值比较,不= =你可以考虑在调试模式下,在应用程序冻结的时候,这不会导致应用程序冻结,它总是返回错误知道,我们没有看到整个画面。也许它会一直循环直到找到“真实”的地方@doctordrive:谢谢你的建议!
    NUM_ALLL_QuestionNames = new String[NUM_ALL_QuestionNames.size()]; //convert ArrayList<String> to String[]
    
    NUM_ALLL_QuestionNames = NUM_ALL_QuestionNames.toArray();