0

我有两个布局,每个布局都有相同数量的 EditText。一种布局是供用户使用的,从空白开始,另一种包含所有答案。

我希望能够使用预定义的答案布局循环并检查用户布局。

我在下面有一些代码,但我认为我错过了一点......我需要更改什么以允许答案editTexts处于不同(且当前未激活)布局的事实?

 public boolean checkAnswer() {
  final int ROW_COUNT = 15;
  final int COL_COUNT = 10;
  final String ROWS[] = {"R1","R2","R3","R4","R5","R6","R7","R8","R9","R10","R11","R12","R13","R14","R15"};
  final String COLS[] = {"C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"};

  for(int i=0; i<ROW_COUNT; i++) {
      for(int j=0; j<COL_COUNT; j++) {
          String a = ROWS[i];
          String b = COLS[j];
          int editTextBaseId = getResources().getIdentifier("box" + a + b, "id", getPackageName());
          int editTextAnswerId = getResources().getIdentifier("boxA" + a + b, "id", getPackageName());
          EditText editTextBase = (EditText)findViewById(editTextBaseId);
          EditText editTextAnswer = (EditText)findViewById(editTextAnswerId);
          String textBase = editTextBase.getText().toString();
          String textAnswer = editTextAnswer.getText().toString();
          if(textBase.equals(textAnswer)) {
          }
          else {
              return false;
          }               
      }
  }        
  return true;         

}

4

1 回答 1

1

为什么需要两种布局?当用户要求答案时,只需在第一个布局中填写答案。

于 2012-12-17T17:43:02.380 回答