我正在做一个字谜游戏,我有一个字符串数组,例如
String[] answers = {"yes", "hello", "goodbye", "after", "christmas"};
我也有一个等级整数
int currentLevel = 0;
现在,当在文本字段中输入答案时,它将使用以下代码将其与数组中当前级别的答案进行比较
TextView currentGuess = findViewById(R.id.currentGuess);
if(currentGuess.getText().toString().equals(answers[currentLevel])) {
//execute code
}
这是非常好的工作,直到它到达数组字3(之后),然后它一直说不正确,我尝试更改单词仍然得到相同的结果,我也尝试在页面上打印答案,只是检查它是否与正确的单词进行比较,一切都很好。
我完全不知道这个,这是我在这场比赛中唯一的障碍。
提前致谢!
答案 0 :(得分:0)
我怀疑你有一个增加currentLevel
的资本水平。尽量做到如下:
TextView currentGuess = findViewById(R.id.currentGuess);
if(currentGuess.getText().toString().toLowerCase().equals(answers[currentLevel])) {
//execute code
}