android注册页面

来源:互联网 发布:excel数据验证限制 编辑:程序博客网 时间:2024/06/14 19:01

效果图

布局文件代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="wrap_content" >    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="center"        android:orientation="vertical" >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="left"            android:orientation="horizontal" >            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:padding="@dimen/padding_medium"                android:text="@string/inputname"                tools:context=".RegisterActivity" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            android:orientation="horizontal" >            <EditText                android:id="@+id/name"                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:inputType="text"                android:padding="@dimen/padding_medium" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="left"            android:orientation="horizontal" >            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:padding="@dimen/padding_medium"                android:text="@string/inputsex"                tools:context=".RegisterActivity" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="left"            android:orientation="horizontal" >            <RadioGroup                android:id="@+id/sex"                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:checkedButton="@+id/girl"                android:orientation="horizontal" >                <RadioButton                    android:id="@id/girl"                    android:text="@string/girl" />                <RadioButton                    android:id="@+id/boy"                    android:text="@string/boy" />            </RadioGroup>        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="left"            android:orientation="horizontal" >            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:padding="@dimen/padding_medium"                android:text="@string/inputbirthday"                tools:context=".RegisterActivity" />        </LinearLayout>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="left"            android:orientation="vertical" >            <DatePicker                android:id="@+id/date"                android:layout_width="wrap_content"                android:layout_height="wrap_content" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:padding="@dimen/padding_medium"                android:text="@string/inputhoby"                tools:context=".RegisterActivity" />            <CheckBox                android:id="@+id/film"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:checked="true"                android:text="@string/film" />            <CheckBox                android:id="@+id/basketball"                android:layout_width="wrap_content"                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" />        </LinearLayout>    </LinearLayout></ScrollView>

activity代码:

package cn.bzu.case1;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.DatePicker;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.Toast;import android.support.v4.app.NavUtils;public class RegisterActivity extends Activity {private EditText name;private String  sex;private DatePicker date;private CheckBox film,basketball;private Button submit;private RadioButton boy,girl;private String birthday;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_register);        name=(EditText) this.findViewById(R.id.name);        boy=(RadioButton) this.findViewById(R.id.boy);        girl=(RadioButton) this.findViewById(R.id.girl);        date=(DatePicker) this.findViewById(R.id.date);        film=(CheckBox) this.findViewById(R.id.film);        basketball=(CheckBox) this.findViewById(R.id.basketball);        submit=(Button) this.findViewById(R.id.submit);        if(boy.isChecked()){        sex=boy.getText().toString();        }else{        sex=girl.getText().toString();        }        birthday=String.valueOf(date.getYear())+"年"+String.valueOf(date.getMonth())+"月"+String.valueOf(date.getDayOfMonth())+"日";        submit.setOnClickListener(new SubmitClickListener());          }    private class SubmitClickListener implements OnClickListener {@Overridepublic void onClick(View v) {String name1=name.getText().toString();String hoby="";if(film.isChecked()){hoby=hoby+film.getText();}if(basketball.isChecked()){hoby=hoby+basketball.getText();}Toast.makeText(RegisterActivity.this, "注册成功!\n" + "您的姓名:"+name1+"\n您的性别:"+sex+"\n您的生日:"+birthday+"\n您的爱好:"+hoby,Toast.LENGTH_LONG).show();}}    @Override    public boolean onCreateOptionsMenu(Menu menu) {        getMenuInflater().inflate(R.menu.activity_register, menu);        return true;    }    }



 

原创粉丝点击