我有两个布局,每个布局都有相同数量的EditTexts。一个布局是针对用户的,并且从空白开始,另一个布局包含所有答案。
我希望能够使用预定义的答案布局循环查看用户布局。
我在下面有一些代码,但我想我有点遗漏了这一点......我需要改变什么才能让答案editTexts处于不同的(当前不是活动的)布局?< / p>
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;
}
答案 0 :(得分:1)
为什么需要两种布局?当用户要求答案时,只需用答案填充第一个布局。