Android registration page

Source: Internet
Author: User

Layout file code:

<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 Code:

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. W Idget. 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. activit Y_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 (). tostri Ng ();} else {sex = girl. gettext (). tostring ();} Birthday = string. valueof (date. getyear () + "year" + String. valueof (date. getmonth () + "month" + String. valueof (date. getdayofmonth () + "day"; Submit. setonclicklistener (New submitclicklistener ();} private class submitclicklistener implements onclicklistener {@ overridepublic void onclick (view v) {string name1 = Name. gettext (). tostring (); string Hoby = ""; if (film. ischecked () {H Oby = Hoby + film. gettext ();} If (basketball. ischecked () {Hoby = Hoby + basketball. gettext ();} toast. maketext (registeractivity. this, "registration successful! \ N "+" Your name: "+ name1 +" \ n your gender: "+ sex +" \ n your birthday: "+ birthday +" \ n your hobbies: "+ Hoby, toast. length_long ). show () ;}@ override public Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_register, menu); Return true ;}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.