Android Studio 实现简易的个人信息录取(含源码)

  • 实现基本的视图效果,有界面跳转功能、对事件的反馈效果等…

具体实现效果

  • 指定名称,并可以跳转其他页面
    在这里插入图片描述
  • 选择个人爱好,可自定义其他爱好
    在这里插入图片描述
  • 选择个人标签,可自定义其他标签
    在这里插入图片描述

参考源码

首页

<?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"
    android:background="@drawable/img1">
    
    <TextView
        android:id="@+id/t01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="个人信息完善"
        android:textColor="@color/white"
        android:textSize="48dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.497"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.139" />
    <TextView
        android:id="@+id/t02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="姓名:"
        android:textColor="@color/white"
        android:textSize="48dp"
        
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.127"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.262" />
    <EditText
        android:id="@+id/input"
        android:layout_width="170dp"
        android:layout_height="60dp"
        android:background="@color/teal_200"
        android:textColor="@color/black"
        android:gravity="center"
        android:hint="请输入..."
        android:clickable="true"

        android:textSize="30dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.8"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.268"/>
    <Button
        android:id="@+id/b01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="->选择爱好"
        android:textSize="36sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.497"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.463"/>
    <Button
        android:id="@+id/b02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="->选择标签"
        android:textSize="36sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.497"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.586"/>
    <Button
        android:id="@+id/b03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="完成"
        android:textSize="30sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.292"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.732"/>
    <Button
        android:id="@+id/b04"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="取消"
        android:textSize="30sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.704"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.732"/>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.p_message02;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = findViewById(R.id.b01);
        Button button2 = findViewById(R.id.b02);

        EditText editText = findViewById(R.id.input);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String m1 = String.valueOf(editText.getText());
                Intent intent1 = new Intent(); //Intent实例化 (此处命名为intent1)
                intent1.setClass(MainActivity.this,ViewActivity1.class);//两界面联系起来
                intent1.putExtra("m1",m1);//传出“m1”值
                startActivity(intent1);//启动指定页面
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String m2 = String.valueOf(editText.getText());
                Intent intent2 = new Intent();
                intent2.setClass(MainActivity.this,ViewActivity2.class);
                intent2.putExtra("m2",m2);
                startActivity(intent2);
            }
        });
    }
}

选择个人爱好

<?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=".ViewActivity1"
    android:background="@drawable/img1">

    <TextView
        android:id="@+id/Zt03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="36dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.09"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.079"/>
    <TextView
        android:id="@+id/Zt04"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="请选择您的爱好"
        android:textColor="@color/white"
        android:textSize="48dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.494"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.176"/>
    <TextView
        android:id="@+id/Zt05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="其他"
        android:textColor="@color/white"
        android:textSize="48dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.87"/>
    <EditText
        android:id="@+id/Zinput2"
        android:layout_width="240dp"
        android:layout_height="80dp"
        android:text=""
        android:textColor="@color/white"
        android:textSize="36dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.777"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.724"/>
    <Button
        android:id="@+id/Zb05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/teal_200"
        android:text="提交"
        android:textSize="36sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.085"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.715"/>

    <CheckBox
        android:id="@+id/Zcheckbox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="敲代码"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.166"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="弹吉他"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.542"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="读书"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.888"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="健身"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.154"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.409"/>
    <CheckBox
        android:id="@+id/Zcheckbox5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="打篮球"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.542"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.409"/>
    <CheckBox
        android:id="@+id/Zcheckbox6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="聊天"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.888"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>
    <CheckBox
        android:id="@+id/Zcheckbox7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="跳舞"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.151"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.4"/>
    <CheckBox
        android:id="@+id/Zcheckbox8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="跑步"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>
    <CheckBox
        android:id="@+id/Zcheckbox9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="睡觉"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.889"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>

</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.p_message02;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ViewActivity1 extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view1);

        Intent intent1 = getIntent();
        TextView textView = findViewById(R.id.Zt03);
        textView.setText(intent1.getStringExtra("name1"));

        CheckBox checkBox1 = findViewById(R.id.Zcheckbox1);
        CheckBox checkBox2 = findViewById(R.id.Zcheckbox2);
        CheckBox checkBox3 = findViewById(R.id.Zcheckbox3);
        CheckBox checkBox4 = findViewById(R.id.Zcheckbox4);
        CheckBox checkBox5 = findViewById(R.id.Zcheckbox5);
        CheckBox checkBox6 = findViewById(R.id.Zcheckbox6);
        CheckBox checkBox7 = findViewById(R.id.Zcheckbox7);
        CheckBox checkBox8 = findViewById(R.id.Zcheckbox8);
        CheckBox checkBox9 = findViewById(R.id.Zcheckbox9);

        EditText editText2 = findViewById(R.id.Zinput2);

        Button button05 = findViewById(R.id.Zb05);

        button05.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str2 = "您的爱好有:";
                boolean b = false;

                str2 += editText2.getText();
                if(checkBox1.isChecked()){
                    str2 += checkBox1.getText()+",";
                    b = true;
                }
                if(checkBox2.isChecked()){
                    str2 += checkBox2.getText()+",";
                    b = true;
                }
                if(checkBox3.isChecked()){
                    str2 += checkBox3.getText()+",";
                    b = true;
                }
                if(checkBox4.isChecked()){
                    str2 += checkBox4.getText()+",";
                    b = true;
                }
                if(checkBox5.isChecked()){
                    str2 += checkBox5.getText()+",";
                    b = true;
                }
                if(checkBox6.isChecked()){
                    str2 += checkBox6.getText()+",";
                    b = true;
                }
                if(checkBox7.isChecked()){
                    str2 += checkBox7.getText()+",";
                    b = true;
                }
                if(checkBox8.isChecked()){
                    str2 += checkBox8.getText()+",";
                    b = true;
                }
                if(checkBox9.isChecked()){
                    str2 += checkBox9.getText()+",";
                    b = true;
                }
                Toast.makeText(ViewActivity1.this, str2, Toast.LENGTH_LONG).show();

            }
        });
    }
}

选择个人标签

?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=".ViewActivity2"
    android:background="@drawable/img1">

    <TextView
        android:id="@+id/Zt08"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"

        android:textColor="@color/white"
        android:textSize="36dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.09"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.079"/>
    <TextView
        android:id="@+id/Zt06"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="请选择您的标签"
        android:textColor="@color/white"
        android:textSize="48dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.494"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.176"/>
    <TextView
        android:id="@+id/Zt07"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="其他"
        android:textColor="@color/white"
        android:textSize="40dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.085"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.715"/>
    <EditText
        android:id="@+id/Zinput"
        android:layout_width="240dp"
        android:layout_height="80dp"
        android:text=""
        android:textColor="@color/white"
        android:textSize="36dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.777"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.724"/>
    <Button
        android:id="@+id/Zb06"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/teal_200"
        android:text="提交"
        android:textSize="36sp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.87"/>

    <CheckBox
        android:id="@+id/Zcheckbox10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="00后"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.166"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="清新"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.542"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="热情"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.888"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.317"/>
    <CheckBox
        android:id="@+id/Zcheckbox13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="高冷"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.154"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.409"/>
    <CheckBox
        android:id="@+id/Zcheckbox14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="搞笑"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.542"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.409"/>
    <CheckBox
        android:id="@+id/Zcheckbox15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="安静"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.889"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.409"/>
    <CheckBox
        android:id="@+id/Zcheckbox16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="健硕"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.151"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>
    <CheckBox
        android:id="@+id/Zcheckbox17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="哲理"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.501"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>
    <CheckBox
        android:id="@+id/Zcheckbox18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="善良"
        android:textColor="@color/white"
        android:textSize="24dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.889"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.499"/>


</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.p_message02;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ViewActivity2 extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view2);

        Intent intent1 = getIntent();
        TextView textView = findViewById(R.id.Zt08);
        textView.setText(intent1.getStringExtra("name2"));

        CheckBox checkBox1 = findViewById(R.id.Zcheckbox10);
        CheckBox checkBox2 = findViewById(R.id.Zcheckbox11);
        CheckBox checkBox3 = findViewById(R.id.Zcheckbox12);
        CheckBox checkBox4 = findViewById(R.id.Zcheckbox13);
        CheckBox checkBox5 = findViewById(R.id.Zcheckbox14);
        CheckBox checkBox6 = findViewById(R.id.Zcheckbox15);
        CheckBox checkBox7 = findViewById(R.id.Zcheckbox16);
        CheckBox checkBox8 = findViewById(R.id.Zcheckbox17);
        CheckBox checkBox9 = findViewById(R.id.Zcheckbox18);

        EditText editText2 = findViewById(R.id.Zinput);

        Button button06 = findViewById(R.id.Zb06);
        button06.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str2 = "已选择标签:";
                //String str0 = "";
                boolean b = false;

                str2 += editText2.getText();
                if (checkBox1.isChecked()) {
                    str2 += checkBox1.getText() + ",";
                    b = true;
                }
                if (checkBox2.isChecked()) {
                    str2 += checkBox2.getText() + ",";
                    b = true;
                }
                if (checkBox3.isChecked()) {
                    str2 += checkBox3.getText() + ",";
                    b = true;
                }
                if (checkBox4.isChecked()) {
                    str2 += checkBox4.getText() + ",";
                    b = true;
                }
                if (checkBox5.isChecked()) {
                    str2 += checkBox5.getText() + ",";
                    b = true;
                }
                if (checkBox6.isChecked()) {
                    str2 += checkBox6.getText() + ",";
                    b = true;
                }
                if (checkBox7.isChecked()) {
                    str2 += checkBox7.getText() + ",";
                    b = true;
                }
                if (checkBox8.isChecked()) {
                    str2 += checkBox8.getText() + ",";
                    b = true;
                }
                if (checkBox9.isChecked()) {
                    str2 += checkBox9.getText() + ",";
                    b = true;
                }
                if (b) {
                    str2 = str2.substring(0, str2.length() - 1);
                }
                Toast.makeText(ViewActivity2.this, str2, Toast.LENGTH_LONG).show();
            }
        });
    }
}

评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值