Kurt
Kurt

Reputation: 777

Checking editText entries against those in a different layout

I have two layouts, each with an identical number of EditTexts. One layout is for the user and starts off blank, another contains all of the answers.

I want to be able to loop through and check the users layout with the pre-defined answer layout.

I have some code below but I think I'm missing the point a bit... what do I need to change to allow for the fact that the answer editTexts are in a different (and not currently active) layout?

 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;         

}

Upvotes: 0

Views: 53

Answers (1)

Vasudev
Vasudev

Reputation: 1996

Why do you need two layouts? Just fill the first layout with answers when user asks for the answers.

Upvotes: 1

Related Questions