我有两个相同的视图和许多editTexts。一方面,在editTexts 中填充了预定义的答案(但未向用户显示)。在第二种情况下,用户从所有空白的 editTexts 开始,然后填写它们以尝试使它们与预定义的答案相同。
所以我想遍历用户的视图,将其与预定义的视图进行检查,直到发现不等式,在这种情况下,该方法将返回 false。
我的代码如下。在 onCreate 我有一个 buttonListener (当用户准备好检查答案时) btnSolution.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkAnswer() == true){
Toast.makeText(getBaseContext(), "all good!", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getBaseContext(), "no good", Toast.LENGTH_LONG).show();
}
}
});
然后将 checkAnswer() 方法定义如下
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;
}
不幸的是,当我尝试运行它时,我的 LogCat 中出现了崩溃和以下错误
12-17 00:05:02.075: E/SKIA(16370): FimgApiStretch:stretch failed
有什么明显的错误吗?