Java implementation simple registration choice City _java

Source: Internet
Author: User

The example of this article for everyone to share the Java implementation of the simple registration of the city of all the code, for your reference, the specific contents are as follows

1.activity_main.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "android:orientation=" vertical "android:layout_width=" fill _parent "android:layout_height=" fill_parent "> <textview android:layout_width=" wrap_content "Android:layout_h" eight= "wrap_content" android:text= "User name:"/> <edittext android:id= "@+id/user" android:minwidth= "200px" and Roid:layout_width= "Wrap_content" android:layout_height= "wrap_content"/> <linearlayout android:gravity= " Center_vertical "android:layout_width=" match_parent "android:layout_height=" wrap_content "> <TextView androi D:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Sex:"/> <RadioGroup A Ndroid:id= "@+id/sex" android:orientation= "horizontal" android:layout_width= "Wrap_content" android:layout_height= " Wrap_content "> <radiobutton AndroId:id= "@+id/radio0" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:checked= "
    True "android:text="/> <radiobutton android:id= "@+id/radio1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "female"/> </RadioGroup> </LinearLayout> <linearla
 Yout android:orientation= "vertical" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" > <textview android:id= "@+id/textview1" android:text= "Please choose your city:" android:layout_height= "Wrap_content" Android: Layout_width= "Wrap_content"/> <spinner android:entries= "@array/ctype" android:layout_height= "Wrap_content" a Ndroid:layout_width= "Wrap_content" android:id= "@+id/spinner1"/> </LinearLayout> <textview android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Password:"/> <EditText android:id= " @+id/pwd "android:minwidth=" 200px "AndroId:inputtype= "Textpassword" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"/> < TextView android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "Confirm password:"/> < EditText android:id= "@+id/repwd" android:minwidth= "200px" android:inputtype= "Textpassword" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "/> <textview android:id=" @+id/textview3 "Android:layout_wid Th= "Wrap_content" android:layout_height= "Wrap_content" android:text= "e-mail address:"/> <edittext android:id= "@+
 
 Id/email "android:minwidth=" 400px "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "/>" <button android:id= "@+id/submit" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Andr oid:text= "Submit"/> </LinearLayout>

2.register.xml 

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/"
 Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical "
  > <textview android:id= "@+id/user" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:padding= "10px" android:text= Username: "/> <textview android:id=" @+id/sex "android:layout_width=" Wrap_con Tent "android:layout_height=" Wrap_content "android:padding=" 10px "android:text=" Sex: "/> <textview Android : id= "@+id/city" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:padding= "10px" an droid:text= "City:"/> <textview android:id= "@+id/pwd" android:layout_width= "Wrap_content" android:layout_he ight= "Wrap_content" android:padding= "10px" android:text= "Password:"/> <textview android:id= "@+id/email" Androi d:padding= "10px" Android:layout_widtH= "Wrap_content" android:layout_height= "Wrap_content" android:text= "e-mail:"/> <button android:id= "@+id/back "Android:text=" returns to the previous step "android:layout_width=" Wrap_content "android:layout_height=" wrap_content "/> </LinearL
 Ayout>

3. mainactivity.java    

Package com.example.ejcker_llin.myapplication;
Import android.app.Activity;
Import android.content.Intent;
Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.AdapterView;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.RadioButton;
Import Android.widget.RadioGroup;
Import Android.widget.Spinner;
 
Import Android.widget.Toast;
 public class Mainactivity extends activity {private Button submit;
 Private String sex1;
 Private String City;
 final int code=0x717;
  @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.layout.activity_main);
 
  submit= (Button) Findviewbyid (r.id.submit); Submit.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {String user= (Edi
    Ttext) Findviewbyid (R.id.user)). GetText (). toString (); String pwd= ((edittext) Findviewbyid (R.ID.PWD)). GetteXT (). toString ();
    String repwd= ((edittext) Findviewbyid (R.ID.REPWD)). GetText (). toString ();
    String email= ((edittext) Findviewbyid (R.id.email)). GetText (). toString ();
    Radiogroup sex= (Radiogroup) Findviewbyid (r.id.sex);
     for (int i=0;i<sex.getchildcount (); i++) {RadioButton r= (RadioButton) Sex.getchildat (i);
      if (r.ischecked ()) {Sex1=r.gettext (). toString ();
     Break
    } Spinner spinner= (Spinner) Findviewbyid (r.id.spinner1); Spinner.setonitemselectedlistener (New Adapterview.onitemselectedlistener () {@Override public void onitemselecte D (adapterview<?> parent, view view, int position, long id) {city=parent.getitematposition (position). toString (
     );
    @Override public void onnothingselected (adapterview<?> parent) {}}); if (! "". Equals (user) &&! "". Equals (PWD) &&! "". Equals (email) {if (!pwd.equals (repwd)) {Toast.maketext (mainactivity.this, "two times entered inconsistent password, please re-enter!") ", Toast.
      Length_long). Show ();
      ((EditText) Findviewbyid (R.ID.PWD)). SetText ("");
      ((EditText) Findviewbyid (R.ID.REPWD)). SetText ("");
     ((EditText) Findviewbyid (R.ID.PWD)). Requestfocus ();
      }else {Intent intent=new Intent (mainactivity.this,registeracivity.class);
      Bundle bundle=new Bundle ();
      Bundle.putcharsequence ("user", user);
      Bundle.putcharsequence ("Sex", sex1);
      Bundle.putcharsequence ("City", city);
      Bundle.putcharsequence ("pwd", PWD);
      Bundle.putcharsequence ("email", email);
      Intent.putextras (bundle);
      StartActivity (Intent);
     Startactivityforresult (Intent,code); }else {toast.maketext (mainactivity.this, "Please enter the registration information complete!")
    ", Toast.length_long). Show ();
 }
   }
  }); }
}

4. registeracivity.java  

Package com.example.ejcker_llin.myapplication;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
 
Import Android.widget.TextView;
 /** * Created by Jcker_llin on 2016/4/5. */public class Registeracivity extends activity{@Override protected void onCreate (Bundle savedinstancestate) {Super
  . OnCreate (Savedinstancestate);
  Setcontentview (R.layout.register);
  Final Intent intent=getintent ();
  Bundle Bundle=intent.getextras ();
  TextView user= (TextView) Findviewbyid (R.id.user);
  User.settext ("Username:" +bundle.getstring ("user"));
  TextView sex= (TextView) Findviewbyid (r.id.sex);
  Sex.settext ("Sex:" +bundle.getstring ("Sex"));
  TextView city= (TextView) Findviewbyid (r.id.city);
  City.settext ("City:" +bundle.getstring ("Cities"));
  TextView pwd= (TextView) Findviewbyid (R.ID.PWD);
  Pwd.settext ("Password:" +bundle.getstring ("pwd"));
  TextView email= (TextView) Findviewbyid (R.id.email); Email.settext ("E-mail: "+bundle.getstring" ("email"));
  Button button= (button) Findviewbyid (R.id.back); Button.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) {Setresult (0x717,i
    Ntent);
 
   Finish ();
 }
  });
 }
}

5.

6.

7. Arrays.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
 <string-array name= "CType" >
  < Item> Beijing </item>
  <item> Shanghai </item>
  <item> Guangzhou </item>
  <item> Hangzhou < /item>
  <item> Tianjin </item>
  <item> Hong Kong </item>
  <item> Chongqing </item>
  <item> Xi ' an </item>
  <item> other </item>
 </string-array>
</ Resources>

The above is the entire content of this article, I hope to help you learn.

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.