我的程序显示一系列问题(逐个问题).在我写完答案后,一条警告信息应告诉我答案是对还是错.
问题是,即使我写了正确的答案,警报消息也会显示“错误”消息.
问题是,即使我写了正确的答案,警报消息也会显示“错误”消息.
final String questions[] = {"Who's Tom?","Who's Luca?","Who's Flavie?"} final String answers[] = {"American","Italian","French"} // display question answer_question.setOnClickListener(new View.OnClickListener() { int CurrentQuestionIndex = 0; public void onClick(View v) { ask_question.setText(question[(CurrentQuestionIndex++) % (questions.length)]); // discuss question versus answer EditText answer = (EditText) findViewById(R.id.tvReponseF); if (answer.equals(answers[CurrentQuestionIndex])) { alertMessageRight(); } else { alertMessageFalse(); } } });
解决方法
问题是您正在将EditText对象与String字段进行比较.您必须将String与String进行比较.
这是怎么做的:
String answer = ((EditText) findViewById(R.id.tvReponseF)).getText().toString(); if(answer.equals(answers[CurrentQuestionIndex])) { ...