Activity用户注册界面

<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"
    tools:context=".MainActivity">
 
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用户名:"
        android:textSize="30dp"
        android:layout_marginTop="30dp"
        android:textColor="#FFA500"
        />
 
    <EditText
        android:layout_width="600dp"
        android:layout_height="wrap_content"
        android:id="@+id/et1"
        android:layout_toRightOf="@id/tv1"
        android:layout_marginTop="20dp"
        android:textSize="30dp"
        />
 
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密    码:"
        android:textSize="30dp"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/tv1"
        android:textColor="#FFA500"
        />
 
    <EditText
        android:id="@+id/et2"
        android:layout_width="600dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2"
        android:layout_marginTop="30dp"
        android:textSize="30dp"
        android:layout_below="@+id/et1"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性别:"
        android:layout_marginLeft="1dp"
        android:layout_below="@id/tv2"
        android:layout_marginTop="20dp"
        android:textSize="40dp"
        android:textColor="#FF0000"/>
<RadioGroup
    android:id="@+id/rb"
    android:layout_width="197dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp">
 
    <RadioButton
        android:id="@+id/rb1"
        android:layout_width="97dp"
        android:layout_height="79dp"
        android:text="男"
        android:textSize="30dp"/>
 
    <RadioButton
        android:id="@+id/rb2"
        android:layout_width="97dp"
        android:layout_height="79dp"
        android:text="女"
        android:textSize="30dp" />
</RadioGroup>
    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="爱好:"
        android:layout_below="@id/rb"
        android:textSize="40dp"
        android:layout_marginLeft="1dp"
        android:textColor="#FF0000"/>
<CheckBox
    android:layout_width="100dp"
    android:layout_height="60dp"
    android:id="@+id/cb1"
    android:layout_toRightOf="@id/tv3"
    android:layout_below="@id/rb"
    android:text="篮球"
    android:textSize="30dp"
    />
 
    <CheckBox
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:id="@+id/cb2"
        android:layout_toRightOf="@id/cb1"
        android:layout_below="@id/rb"
        android:text="足球"
        android:textSize="30dp"
        />
    <CheckBox
        android:layout_width="100dp"
        android:layout_height="60dp"
        android:id="@+id/cb3"
        android:layout_toRightOf="@id/cb2"
        android:layout_below="@id/rb"
        android:text="排球"
        android:textSize="30dp"
        />
    <Button
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/cb1"
        android:layout_centerHorizontal="true"
        android:text="注册"
        android:textSize="45dp"
        android:onClick="click"
        android:layout_marginTop="10dp"
        />
</RelativeLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".TheSecond">
 
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/tv1"
       android:text="你的注册信息是:"
       android:textSize="30dp"
       android:layout_centerHorizontal="true"
       android:layout_marginTop="20dp"
       android:layout_marginBottom="50dp"
       />
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用户名:"
        android:textSize="20dp"
        android:layout_below="@id/tv1"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et1"
        android:layout_marginTop="4dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/tv1"
        />
    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密    码:"
        android:textSize="20dp"
        android:layout_below="@id/tv2"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et2"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et1"
        />
    <TextView
        android:id="@+id/tv4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性    别:"
        android:textSize="20dp"
        android:layout_below="@id/tv3"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et3"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et2"
        />
    <TextView
        android:id="@+id/tv5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="爱    好:"
        android:textSize="20dp"
        android:layout_below="@id/tv4"
        />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et4"
        android:layout_marginTop="8dp"
        android:layout_toRightOf="@id/tv2"
        android:layout_below="@id/et3"
        />
 
 
</RelativeLayout>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.register;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
 
public class MainActivity extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
    public void click(View v){
        String name =((EditText)findViewById(R.id.et1)).getText().toString();
        String password =((EditText)findViewById(R.id.et2)).getText().toString();
        Intent it1=new Intent(this,TheSecond.class);
        it1.putExtra("name",name);
        it1.putExtra("password",password);
        final RadioGroup size =(RadioGroup)findViewById(R.id.rb);
        int selected=size.getCheckedRadioButtonId();
 
        switch (selected){
            case R.id.rb1:
                it1.putExtra("boy","男");
                break;
            case R.id.rb2:
                it1.putExtra("girl","女");
                break;
        }
        CheckBox c1=(CheckBox)findViewById(R.id.cb1);
        CheckBox c2=(CheckBox)findViewById(R.id.cb2);
        CheckBox c3=(CheckBox)findViewById(R.id.cb3);
        if(c1.isChecked()){
            it1.putExtra("bask","篮球");
        }
        if(c2.isChecked()){
            it1.putExtra("foot","足球");
        }
        if(c3.isChecked()){
            it1.putExtra("volley","排球");
        }
        startActivity(it1);
    }
 
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.register;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
 
public class TheSecond extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_the_second);
    }
 
    @Override
    protected void onStart() {
        super.onStart();
 
        Intent intent =getIntent();
        String name=intent.getStringExtra("name");
        String password=intent.getStringExtra("password");
        String boy=intent.getStringExtra("boy");
        String girl=intent.getStringExtra("girl");
        String bask=intent.getStringExtra("bask");
        String foot=intent.getStringExtra("foot");
        String volley=intent.getStringExtra("volley");
        TextView a=(TextView)findViewById(R.id.et1);
        TextView b=(TextView)findViewById(R.id.et2);
        TextView c=(TextView)findViewById(R.id.et3);
        TextView d=(TextView)findViewById(R.id.et4);
        a.setText(name);
        b.setText(password);
        if (bask==null){
            bask="";
        }
        if(foot==null){
            foot="";
        }
        if (volley==null){
            volley="";
        }
        if (girl==null){
            girl="";
        }
        if(boy==null){
            boy="";
        }
        c.setText(girl+boy);
        d.setText(bask+foot+volley);
    }
}

  用户主界面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.register">
 
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
 
        <activity
            android:name=".TheSecond"
            android:label="@string/app_name">
            </activity>
 
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
    </application>
 
</manifest>
原文地址:https://www.cnblogs.com/fanbudufan/p/13986243.html