设计用户注册页面

设计用户注册页面知识点:

掌握以下UI组件的使用
CheckBox用于选取多个值时使用的组件,在布局文件中使用<CheckBox>标签标记,可以使用android:checked=“true”来设定默认选中值。
DatePicker组件可以输入日期。范围在1900-1-1 ~ 2100-12-31
RadioButton可以构建一组单选按钮,一组互斥的单选按钮必须在用一个RadioGroup中。
Toast:弹出提示框
ScrollView的使用:当一屏显示不开时,自动加入滚动条,此时布局文件中ScrollView处于顶级元素
 

运行效果图:

 

 

注册页面的布局文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/label_name" />

        <EditText
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/label_sex" />

        <RadioGroup
            android:id="@+id/sex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="@string/male" />

            <RadioButton
                android:id="@+id/female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/female" />
        </RadioGroup>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/label_birth" />

        <DatePicker
            android:id="@+id/birth"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/label_interest" />

        <CheckBox
            android:id="@+id/movie"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/movie" />

        <CheckBox
            android:id="@+id/basketball"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/basketball" />

        <Button
            android:id="@+id/submit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_submit" >
        </Button>
    </LinearLayout>

</ScrollView>


注册成功时弹出注册信息

public class RegisterActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		final EditText nameText = (EditText) this.findViewById(R.id.name);
		final RadioButton maleRadio = (RadioButton) this
				.findViewById(R.id.male);
		final RadioButton femaleRadio = (RadioButton) this
				.findViewById(R.id.female);
		final DatePicker birthDatePicker = (DatePicker) this
				.findViewById(R.id.birth);
		final CheckBox movieBox = (CheckBox) this.findViewById(R.id.movie);
		final CheckBox basketballBox = (CheckBox) this
				.findViewById(R.id.basketball);
		Button submit = (Button) this.findViewById(R.id.submit);
		submit.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				String sex = "男";

				if (maleRadio.isChecked()) {
					sex = maleRadio.getText().toString();
				}
				if (femaleRadio.isChecked()) {
					sex = femaleRadio.getText().toString();
				}

				String interest = "";
				if (movieBox.isChecked()) {
					interest = interest + movieBox.getText().toString();
				}
				if (basketballBox.isChecked()) {
					interest = interest + basketballBox.getText().toString();
				}
				String birth = birthDatePicker.getYear() + "年"
						+ (birthDatePicker.getMonth() + 1) + "月"
						+ birthDatePicker.getDayOfMonth() + "日";
				StringBuffer prompt = new StringBuffer();
				prompt.append("注册成功!\n您的姓名:")
						.append(nameText.getText().toString())
						.append("\n您的性别是:").append(sex).append("\n您的生日:")
						.append(birth).append("\n您的爱好:").append(interest);
				Toast.makeText(RegisterActivity.this, prompt, Toast.LENGTH_LONG)
						.show();
			}
		});
	}
}


 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值