[英]I am going to develop a new Quiz application in Android. When I click on the wrong option it has to show red color how can we do that?
I am new to this Quiz Applications. 我是这个测验应用程序的新手。
I am using radio buttons here. 我在这里使用单选按钮。 When I click on wrong options it will come on red color and it has to display correct answer also. 当我单击错误的选项时,它将变为红色,并且还必须显示正确的答案。 Now here is my code. 现在这是我的代码。 When i click on the next button it will appear like this. 当我单击下一个按钮时,它将显示如下。 Thanks in advance. 提前致谢。 here total, correct and wrong are static variables to display the final score in another class. 这里的合计,正确和错误是静态变量,用于显示另一个班级的最终分数。
RadioButton uans = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
if (ansText.equalsIgnoreCase(answers[flag])) {
correct++;
} else {
wrong++;
}
flag++;
if (flag < question.length) {
tv.setText(question[flag]);
rb1.setText(options[flag * 3]);
rb2.setText(options[flag * 3 + 1]);
rb3.setText(options[flag * 3 + 2]);
marks = correct - wrong;
} else {
marks = correct - wrong;
Intent in = new Intent(getApplicationContext(),
ResultActivity.class);
startActivity(in);
}
if (flag == question.length) {
Intent in = new Intent(getApplicationContext(),
ResultActivity.class);
startActivity(in);
Level1Activity.this.finish();
}
total = question.length;
add these statement where you find a wrong ans, that is in else part, where you need to set a red color. 在发现错误的ans的地方添加这些语句,即在其他地方需要设置红色的地方。
if your color.xml is like: 如果您的color.xml是这样的:
<color name="errorColor">#f00</color>
then 然后
uans.setTextColor(getResources().getColor(R.color.red));
and also set the ans with another color 并设置另一种颜色的ans
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.