我正在使用分配的特定 Java 代码块,目前在 1 页上我使用它超过 30 次。这是因为在每个代码块中,对于我进行的每次比较,所有数字都需要增加 1。(示例 1)有没有办法编写一些将使用中的数字增加 1 的代码(就像您通常使用增量代码一样)。如果是这样,这在调用资源时也是可能的(示例 2)
具体代码块:
// Comparison 1
if (Uinput1.equals(answer1)) {
edit1.setBackgroundColor(Color.parseColor("#00FF00"));
}
else {
edit1.setBackgroundColor(Color.parseColor("#FF0000"));
}
第二次使用等等。
// Comparison 2
if (Uinput2.equals(answer2)) {
edit2.setBackgroundColor(Color.parseColor("#00FF00"));
}
else {
edit2.setBackgroundColor(Color.parseColor("#FF0000"));
}
声明资源等
private String answer1;
private String answer2;`
this.answer1 = getString(R.string.answer1);
this.answer2 = getString(R.string.answer2);`
this.answer1 = getString(R.string.answer1);
this.answer2 = getString(R.string.answer2);
this.edit1 = findViewById(R.id.edit1);
this.edit2 = findViewById(R.id.edit2);
String Uinput1 = edit1.getText().toString();
String Uinput2 = edit2.getText().toString();
编辑:
我在第一部分使用了这个:
private String[] answers = {"example", "example"}
汪汪一只猫
弑天下
相关分类