我正在将来自 a 的输入TextEdit与来自“answerList”的答案进行比较。现在我想知道:为什么不.equals()比较“uinput” String?有人可以向我解释这一点并在代码中使用它吗?
提前致谢,祝您有美好的一天!
package ...
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public TextView view1;
public String uinput;
public EditText edit1;
public TextView score_view;
public int score = 0;
public String[] questionList = {
"lux, luces",
"munus, munera",
"neglere",
};
public String[] answerList = {
"(dag)licht, dag",
"taak",
"verwaarlozen",
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.edit1 = findViewById(R.id.edit1);
this.view1 = findViewById(R.id.view1);
this.score_view = findViewById(R.id.score_view);
this.uinput = edit1.getText().toString();
view1.setText(questionList[0]);
}
public void check(View view) {
if (uinput.equals(answerList[0])) {
edit1.setBackgroundColor(Color.parseColor("#00FF00"));
score++;
score_view.setText(score);
} else {
edit1.setBackgroundColor(Color.parseColor("#FF0000"));
}
}
}
慕桂英4014372
相关分类