试卷的xml代码如下
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="20dp" android:id="@+id/one"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="单选" android:textColor="#FF0000" android:layout_above="@id/two"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40dp" android:text="1、安卓有几大控件?(5分)" android:background="#5903A9F4" /> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="一大控件" android:textSize="30dp" android:id="@+id/a_1" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="三大控件" android:textSize="30dp" android:id="@+id/a_2" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="四大控件" android:textSize="30dp" android:id="@+id/a_3" /> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="30dp" android:layout_below="@id/one" android:id="@+id/two" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="多选" android:textColor="#FF0000" android:layout_above="@id/two"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="40dp" android:text="2、错误的更新UI的方式是?(5分)" android:background="#5903A9F4" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="在主线程内" android:textSize="30dp" android:id="@+id/b_1" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="在字线程内" android:textSize="30dp" android:id="@+id/b_2" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="主线程或者子线程内" android:textSize="30dp" android:id="@+id/b_3" /> </LinearLayout> <Button android:layout_below="@id/two" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/submit" android:text="提交" android:background="@drawable/ic_launcher_background" android:textSize="40dp"/> <TextView android:layout_below="@id/two" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/result" android:textColor="#f00" android:textSize="40dp"/> </RelativeLayout>class
package com.jiang.jzj_qq.Papers; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.TextView; import com.jiang.jzj_qq.R; public class Text extends AppCompatActivity { private LinearLayout one; private RadioButton a1; private RadioButton a2; private RadioButton a3; private LinearLayout two; private Button submit; private TextView result; private CheckBox b1; private CheckBox b2; private CheckBox b3; private AlertDialog dialog; private int score = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text); findViews(); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //加载进度条 final ProgressDialog progressDialog = new ProgressDialog(Text.this); progressDialog.setTitle("正在加载..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < 100; i++) { progressDialog.setProgress(i); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } progressDialog.dismiss(); } }).start(); progressDialog.show(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } //判断 dialog = new AlertDialog.Builder(Text.this) .setTitle("是否确认提交") .setNegativeButton("再看看",null)//负极 .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { score = 0; if(a3.isChecked()){ score+=5; } if(b2.isChecked() && b3.isChecked() && !b1.isChecked()){ score+=5; } result.setText("得分:"+score); } }).create(); dialog.show(); } }); } private void findViews() { one = (LinearLayout)findViewById( R.id.one ); a1 = (RadioButton)findViewById( R.id.a_1 ); a2 = (RadioButton)findViewById( R.id.a_2 ); a3 = (RadioButton)findViewById( R.id.a_3 ); two = (LinearLayout)findViewById( R.id.two ); b1 = (CheckBox)findViewById( R.id.b_1 ); b2 = (CheckBox)findViewById( R.id.b_2 ); b3 = (CheckBox)findViewById( R.id.b_3 ); submit = (Button)findViewById( R.id.submit ); result = (TextView)findViewById(R.id.result); } }