单选详细代码实现

单选详细代码实现

效果图
在这里插入图片描述

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity{

    private TextView tv;
    private RadioGroup rg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rg = (RadioGroup) findViewById(R.id.rg);
        tv = (TextView)findViewById(R.id.tv);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId == R.id.rg_rb_boy){
                    tv.setText("您选择的是男!");
                }else{
                    tv.setText("您选择的是女!");
                }
            }
        });
    }



}

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <RadioGroup
            android:id="@+id/rg"
            style="@style/general">
            <RadioButton
                android:id="@+id/rg_rb_boy"
                style="@style/general"
                android:text=""/>
            <RadioButton
                android:id="@+id/rg_rb_girl"
                style="@style/general"
                android:text=""/>
        </RadioGroup>
        <TextView
            android:id="@+id/tv"
            style="@style/general"
            android:layout_gravity="center"
            android:text=""
            />
    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="general">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textSize">25sp</item>
    </style>
</resources>

第一次弄的,大家给点意见 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>低碳问卷1</title> </head> <body> <div align="center"> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var ans = new Array; var done = new Array; var yourAns = new Array; var explainAnswer = new Array; var score = 0; ans[1] = "b"; ans[2] = "b"; ans[3] = "a"; ans[4] = "c"; ans[5] = "b"; explainAnswer[1]="你的回答是不正确,努力哟!"; explainAnswer[2]="你的回答是不正确,努力哟!"; explainAnswer[3]="你的回答是不正确,努力哟!"; explainAnswer[4]="你的回答是不正确,努力哟!"; explainAnswer[5]="你的回答是不正确,努力哟!"; function Engine(question, answer) { yourAns[question]=answer; } function Score(){ var answerText = "看看你的成绩如何?\n------------------------------------\n"; for(i=1;i<=5;i++){ answerText=answerText+"\n问题:"+i+"\n"; if(ans[i]!=yourAns[i]){ answerText=answerText+"\n正常的答案是: "+ans[i]+"\n"+explainAnswer[i]+"\n"; } else{ answerText=answerText+" \n对的 \n"; score++; } } answerText=answerText+"\n\n你的成绩是 : "+score+"\n"; //now score the user answerText=answerText+"\n结论 : "; if(score<=0){ answerText=answerText+"你应该好好多学点了!"; } if(score>=1 && score <=2){ answerText=answerText+"你还是有些知识欠缺的!"; } if(score>=3 && score <=3){ answerText=answerText+"做的还不错,但还需要努力!"; } if(score>4){ answerText=answerText+"哇,你可真是厉害,高手,高手!!"; } alert(answerText); } // End --> </script><br> <b><font color="#FF0000" size="5">低碳问卷1</font></b></div> <p align="center" style="margin-top: 5px; margin-bottom: 0"><br> <b><font color="#000000">(同学们点击相应选项,完成后点击查看成绩按钮可查看结果。)</font></b></p> <hr color="#FF0000"> <FORM> <b>1.“低碳”是指 _____。</b><br> <input type=radio name="q1" value="a" onClick="Engine(1, this.value)">a) 减少碳水化合物<br> <input type=radio name="q1" value="b" onClick="Engine(1, this.value)">b) 减少二氧化碳排放<br> <input type=radio name="q1" value="c" onClick="Engine(1, this.value)">c) 减少一氧化碳排放<br> <input type=radio name="q1" value="d" onClick="Engine(1, this.value)">d) 减少碳金属<p> <b>2. 家居用电:二氧化碳排放量(kg)=耗电度数×_____?</b><br> <input type=radio name="q2" value="a" onClick="Engine(2, this.value)">a) 0.275<br> <input type=radio name="q2" value="b" onClick="Engine(2, this.value)">b) 0.785<br> <input type=radio name="q2" value="c" onClick="Engine(2, this.value)">c) 0.89<br> <input type=radio name="q2" value="d" onClick="Engine(2, this.value)">d) 1.25<p> <b>3.每个家庭每使用一度电,相当于排放了_____公斤的二氧化碳。 </b><br> <input type=radio name="q3" value="a" onClick="Engine(3, this.value)">a) 1.5 <br> <input type=radio name="q3" value="b" onClick="Engine(3, this.value)">b) 0.45<br> <input type=radio name="q3" value="c" onClick="Engine(3, this.value)">c) 0.15<br> <input type=radio name="q3" value="d" onClick="Engine(3, this.value)">d) 0.785<p> <b>4. 短时间不用电脑时,启用_____模式,能耗可下降到50%以下?</b><br> <input type=radio name="q4" value="a" onClick="Engine(4, this.value)">a) 屏幕保护<br> <input type=radio name="q4" value="b" onClick="Engine(4, this.value)">b) 开机模式<br> <input type=radio name="q4" value="c" onClick="Engine(4, this.value)">c) 睡眠模式<br> <input type=radio name="q4" value="d" onClick="Engine(4, this.value)">d) 关闭显示器<p> <b>5. 如果全国3.5亿烟民1天少抽1支烟,每年能节约准煤5万吨,减排二氧化碳_____?( </b><br> <input type=radio name="q5" value="a" onClick="Engine(5, this.value)">a) 15万吨<br> <input type=radio name="q5" value="b" onClick="Engine(5, this.value)">b) 21万吨<br> <input type=radio name="q5" value="c" onClick="Engine(5, this.value)">c) 18万吨<br> <input type=radio name="q5" value="d" onClick="Engine(5, this.value)">d) 13万吨<p> <CENTER> <input type=button onClick="Score()" value="看看我的成绩?"> </CENTER> </FORM> </body> </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

365JHWZGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值