提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 运行图
- 代码
一、运行图
运行效果:
二、代码
MainActivity.java 代码如下(示例):
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private EditText edit; private RadioGroup genderGroup; private RadioButton male,female; private String info="",sex="",major="",hobby=""; private Button btn1,btn2; private Spinner spinner; private List<String> majorlist; private CheckBox hobby1,hobby2,hobby3,hobby4; private Toast toast; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edit=findViewById(R.id.edit); genderGroup=findViewById(R.id.genderGroup); male=findViewById(R.id.male); female=findViewById(R.id.female); spinner=findViewById(R.id.spinner); hobby1=findViewById(R.id.hobby1); hobby2=findViewById(R.id.hobby2); hobby3=findViewById(R.id.hobby3); hobby4=findViewById(R.id.hobby4); btn1=findViewById(R.id.btn1); btn2=findViewById(R.id.btn2); genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { RadioButton rd&#