<Android考证之实训项目四>用户注册对话框设计

项目截图

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".RegisterActivity">
 9 
10     <TextView
11         android:layout_width="match_parent"
12         android:layout_height="wrap_content"
13         android:text="请输入您的注册信息"
14         android:textSize="24sp" />
15 
16     <LinearLayout
17         android:layout_width="match_parent"
18         android:layout_height="wrap_content"
19         android:orientation="horizontal">
20 
21         <TextView
22             android:layout_width="wrap_content"
23             android:layout_height="wrap_content"
24             android:layout_weight="1"
25             android:text="用户名:"
26             android:textSize="24sp" />
27 
28         <EditText
29             android:id="@+id/username"
30             android:layout_width="wrap_content"
31             android:layout_height="wrap_content"
32             android:layout_weight="1"
33             android:ems="10" />
34     </LinearLayout>
35 
36     <LinearLayout
37         android:layout_width="match_parent"
38         android:layout_height="wrap_content"
39         android:orientation="horizontal">
40 
41         <TextView
42             android:layout_width="wrap_content"
43             android:layout_height="wrap_content"
44             android:layout_weight="1"
45             android:text="密码:"
46             android:textSize="24sp" />
47 
48         <EditText
49             android:id="@+id/password"
50             android:layout_width="wrap_content"
51             android:layout_height="wrap_content"
52             android:layout_weight="1"
53             android:ems="10" />
54     </LinearLayout>
55 
56     <LinearLayout
57         android:layout_width="match_parent"
58         android:layout_height="wrap_content"
59         android:gravity="center"
60         android:orientation="horizontal">
61 
62         <TextView
63             android:layout_width="wrap_content"
64             android:layout_height="wrap_content"
65             android:text="性别:"
66             android:textSize="24sp" />
67 
68         <RadioGroup
69             android:layout_width="wrap_content"
70             android:layout_height="wrap_content"
71             android:layout_weight="1"
72             android:orientation="horizontal">
73 
74             <RadioButton
75                 android:id="@+id/male"
76                 android:layout_width="wrap_content"
77                 android:layout_height="match_parent"
78                 android:layout_marginLeft="100dp"
79                 android:layout_weight="1"
80                 android:text="男" />
81 
82             <RadioButton
83                 android:id="@+id/female"
84                 android:layout_width="wrap_content"
85                 android:layout_height="wrap_content"
86                 android:layout_weight="1"
87                 android:text="女" />
88         </RadioGroup>
89     </LinearLayout>
90 
91     <Button
92         android:id="@+id/register"
93         android:layout_width="match_parent"
94         android:layout_height="wrap_content"
95         android:text="注册" />
96 </LinearLayout>
activity_register.xml
 1 package com.example.register;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.Button;
 8 import android.widget.EditText;
 9 import android.widget.RadioButton;
10 
11 public class RegisterActivity extends AppCompatActivity {
12 
13     private EditText username;
14     private EditText password;
15     private RadioButton male;
16     private RadioButton female;
17     private Button register;
18 
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.activity_register);
23         username = (EditText)findViewById(R.id.username);
24         password = (EditText)findViewById(R.id.password);
25         male = (RadioButton)findViewById(R.id.male);
26         female = (RadioButton)findViewById(R.id.female);
27         register = (Button)findViewById(R.id.register);
28         register.setOnClickListener(new View.OnClickListener() {
29             @Override
30             public void onClick(View v) {
31                 Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
32                 intent.putExtra("username",username.getText().toString());
33                 intent.putExtra("password",password.getText().toString());
34                 if(male.isChecked()){
35                     intent.putExtra("sex","男");
36                 }
37                 if(female.isChecked()){
38                     intent.putExtra("sex","女");
39                 }
40                 startActivity(intent);
41             }
42         });
43     }
44 }
RegisterActivity.java
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".MainActivity" >
 9 
10     <TextView
11         android:id="@+id/username"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:text="您的用户名为:"
15         android:textSize="24sp" />
16 
17     <TextView
18         android:id="@+id/password"
19         android:layout_width="match_parent"
20         android:layout_height="wrap_content"
21         android:text="您的密码为:"
22         android:textSize="24sp" />
23 
24     <TextView
25         android:id="@+id/sex"
26         android:layout_width="match_parent"
27         android:layout_height="wrap_content"
28         android:text="您的性别为:"
29         android:textSize="24sp" />
30 </LinearLayout>
activity_main.xml
 1 package com.example.register;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.widget.TextView;
 7 
 8 public class MainActivity extends AppCompatActivity {
 9 
10     private TextView username;
11     private TextView password;
12     private TextView sex;
13     @Override
14     protected void onCreate(Bundle savedInstanceState) {
15         super.onCreate(savedInstanceState);
16         setContentView(R.layout.activity_main);
17         username = (TextView)findViewById(R.id.username);
18         password = (TextView)findViewById(R.id.password);
19         sex = (TextView)findViewById(R.id.sex);
20         Intent intent = getIntent();
21         username.setText(username.getText().toString()+intent.getStringExtra("username"));
22         password.setText(password.getText().toString()+intent.getStringExtra("password"));
23         sex.setText(sex.getText().toString()+intent.getStringExtra("sex"));
24     }
25 }
MainActivity.java

 

转载于:https://www.cnblogs.com/jdxb/p/10930059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值