Andriod Studio实现简单的个人信息注册

功能:

  1. 输入用户名、密码
  2. 单选框选择性别
  3. 下拉框选择地址
  4. 复选框选择爱好
  5. 点击按钮提交信息到结果页面
  6. 输入框为空提示
  7. 结果页面显示填写的所有内容
  8. 结果页面可以跳转回首页

效果图

    

MainActivity.java(主要功能)

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        zc=findViewById(R.id.button);//寻找注册按钮id
        zc.setOnClickListener(this);//给注册按钮安装监听器
        rg=findViewById(R.id.rg);//寻找单选组控件id
        rg.setOnCheckedChangeListener(this);//给单选组安装监听器
        rb1=findViewById(R.id.rb1);//寻找单选控件1id
        rb1.setOnCheckedChangeListener(this);//给单选控件1安装监听器
        rb2=findViewById(R.id.rb2);//寻找单选控件2id
        rb2.setOnCheckedChangeListener(this);//给单选控件2安装监听器
        cb1=findViewById(R.id.cb1);//寻找复选框1控件id
        cb1.setOnCheckedChangeListener(this);//给复选框控件1安装监听器
        cb2=findViewById(R.id.cb2);//寻找复选框2控件id
        cb2.setOnCheckedChangeListener(this);//给复选框控件2安装监听器
        cb3=findViewById(R.id.cb3);//寻找复选框3控件id
        cb3.setOnCheckedChangeListener(this);//给复选框控件3安装监听器
        cb4=findViewById(R.id.cb4);//寻找复选框3控件id
        cb4.setOnCheckedChangeListener(this);//给复选框控件3安装监听器
        et1=findViewById(R.id.et1);//寻找输入框1控件id
        et2=findViewById(R.id.et2);//寻找输入框2控件id
        tv=findViewById(R.id.tv);//寻找输入框2控件id
        sp1=(Spinner)findViewById(R.id.sp1);
        ArrayAdapter<String>spinerAda=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,countryList);
        sp1.setAdapter(spinerAda);
        sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                Country=countryList[i];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        sp2=(Spinner)findViewById(R.id.sp2);
        ArrayAdapter<String>spinnerCy=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,cityList);
        sp2.setAdapter(spinnerCy);
        sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                City=cityList[i];
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }


//实现选项按钮组交互功能
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.rb1:
                Gender=rb1.getText().toString();
                break;
            case R.id.rb2:
                Gender=rb2.getText().toString();
                break;
        }

    }
public void onClick(View view){
        String hobbyList =hobby.toString();
        if (strname.equals("")||strPassword.equals(""))//判断用户名是否为空
            tv.setText("注册失败!用户名或密码不能为空");//如果任意一条为空的话执行结果文本框输出内容为"注册失败!用户名或密码不能为空"
        else
        {
            tv.setText("注册成功!即将跳转个人中心页");//否则执行结果文本框输出内容为"注册成功!"
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    String userName =et1.getText().toString();
                    Intent intent =new Intent();
                    intent.setClass(MainActivity.this,InfoActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("name",userName);
                    bundle.putString("gender",Gender);
                    bundle.putString("country",Country);
                    bundle.putString("city",City);
                    bundle.putString("hobby",hobbyList);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            },1000);

        }
    }

 activity_main.xml

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="30dp"
        android:text="用户名:"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.047"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.064" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="72dp"
        android:ems="10"
        android:hint="请输入你的用户名"
        android:inputType="textPersonName"
        app:layout_constraintStart_toEndOf="@+id/textView"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="56dp"
        android:layout_marginLeft="56dp"
        android:layout_marginTop="28dp"
        android:text="密码:"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et1" />
    <EditText
        android:id="@+id/et2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        android:ems="10"
        android:hint="请输入你的密码"
        android:inputType="textPassword"
        app:layout_constraintStart_toEndOf="@+id/textView2"
        app:layout_constraintTop_toBottomOf="@+id/et1" />
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="24dp"
        android:text="性别"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et2" />
    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="30dp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="60dp"
        android:orientation="horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/et2">
        <RadioButton
            android:id="@+id/rb1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="男"/>
        <RadioButton
            android:id="@+id/rb2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="女"/>
        </RadioGroup>

    <TextView
        android:id="@+id/TextView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="24dp"
        android:text="请选择国家:"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/rg"/>
    <Spinner
        android:id="@+id/sp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:spinnerMode="dialog"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/TextView5"/>
    <Spinner
        android:id="@+id/sp2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:spinnerMode="dialog"
        android:layout_marginStart="28dp"
        android:layout_marginLeft="28dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/sp1"/>

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="415dp"
        android:layout_height="59dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/sp2" >

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="30dp"
            android:text="兴趣爱好"
            />

        <CheckBox
            android:id="@+id/cb1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="足球"
            app:layout_constraintStart_toStartOf="parent" />

        <CheckBox
            android:id="@+id/cb2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="篮球"
            app:layout_constraintStart_toStartOf="parent" />

        <CheckBox
            android:id="@+id/cb3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="台球"
            app:layout_constraintStart_toStartOf="parent" />

        <CheckBox
            android:id="@+id/cb4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="网球"
            app:layout_constraintStart_toStartOf="parent" />
    </LinearLayout>



    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="36dp"
        android:text="注册"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ll1" />

activity_info.xml

<TextView
        android:id="@+id/tv2"
        android:layout_width="389dp"
        android:layout_height="205dp"
        android:text=""
        android:textColor="#333"
        android:textSize="24dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.047"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.064" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="36dp"
        android:text="返回"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv2"  />

 

项目包具体资源:Andriod Studio实现简单的个人信息注册(无数据库版)​​​​​​​

  • 16
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

vivi____

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

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

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

打赏作者

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

抵扣说明:

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

余额充值