简体   繁体   English

我将在Android中开发一个新的Quiz应用程序。 当我单击错误的选项时,它必须显示红色,我们该怎么做?

[英]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.

相关问题 我在android中定义动作栏。 如何为每个操作添加新操作和点击侦听器? - I am defining actionbars in android. How do I add new actions and on click listener to each action? 安卓 如何在点击时更改ListView文本颜色? - Android. How can I change a ListView text color on click? 在Android上使用Cordova。 如何显示后台通知? - Using Cordova with Android. How do I show background Notification? 我想在 Android 中开发一个基于问答游戏的应用程序 - I want to develop a quiz game based application in Android 您好,我正在做一个android测验,当问题完成但转到结果活动时,转到结果活动 - Hello, I am making an android quiz to go to the result activity when questions are completed but its not going to result activity 我是Android新手。 我希望仅在服务启动时使用android服务来阻止通话 - I am new to android. I wish to use android service for blocking call only when the service is started 在Android中扩展EditText。 我究竟做错了什么? - Extending a EditText in Android. What am I doing wrong? 我如何在Android中更改/修改状态栏的高度。 我们可以通过反射来做还是可以在android中修改dimen.xml文件 - how can i change/modify the height of status bar in android. can we do by reflection or can we modify the dimen.xml file in android 我只想在android中单击新图片时启动服务。 我该怎么做? - I want to start a service only when a new picture is clicked in android. How do I go about doing that? 开发Android应用程序时,如何退出此应用程序? - When I develop an Android application ,how to exit this application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM