Die Beispiele in diesem Artikel teilen alle Codes für Java, um eine einfache Registrierung zu implementieren und die Stadt auszuwählen, in der sie sich für Ihre Referenz befinden. Der spezifische Inhalt ist wie folgt
1.Activity_main.xml
<? Android: layout_width = "fill_parent" Android: layout_Height = "fill_parent"> <textView Android: layout_width = "Wrap_Content" Android: layout_Height = "Wrap_Content" Android: text = "userername:" /> <redTtext android: id. android: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 android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="gender:" /> <RadioGroup android: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="male"/> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" Android: text = "Frau"/> </radioGroup> </linearlayout> <linearlayout Android: Orientierung = "Vertikal" Android: layout_width = "Wrap_Content" Android: layout_Height = "Wrack_Content"> <textView android: id = "@+id/textView1" und text: text: text: "@+id/textview1" android: text: text: "@+id/textview1" android: text: "@+id/textview1" android: text: "@+id/textview1" android: text: "@+id/textview1" und text: "@+id/textview1" und text: "@+id/textvie Android: layout_Height = "Wrap_Content" Android: layout_width = "Wrap_Content"/> <Spinnner Android: Einträge = "@array/ctype" Android: layout_Height = "Wrap_Content" Android: Layout_widthth = "Wrack_Content" und id. <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="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="E-mail address:" /> <EditText Android: id = "@+id/E -Mail" Android: minwidth = "400px" Android: layout_width = "Wrap_Content" Android: layout_Height = "Wrap_Content"/> <button Android: id = "@+id/subrod: Android: text = "Senden" /> < /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:layout_height="match_parent" android:layout_height="wrap_content" android:padding="10px" android:text="username:" /> <TextView android:id="@+id/sex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" android:text="gender:" /> <TextView android:id="@+id/city" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" android:text="city:" /> <TextView android:id="@+id/pwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" android:text="password:" /> <TextView android:id="@+id/email" android:padding="10px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="E-mail:" /> <Button Android: id = "@+id /zurück" Android: text = "Zurück zum vorherigen Schritt" Android: layout_width = "Wrap_Content" Android: layout_Height = "Wrap_Content" /> < /linearlayout>
3. MainActivity.java
paket com.example.ejcker_llin.myapplication; importieren android.app.Activity; import android.content.intent; import android.support.v7.app.appcompataktivität; import Android.os.bundle android.view.view; importieren android.widget.Adapterview; Import und ROID.WIDGE.Button; android.widget.radiobutton; import android.widget.radioGroup; import android.widget.spinners; import Android.widget.toast; MainActivity der öffentlichen Klasse erweitert die Aktivität {private Schaltfläche Senden; private String sex1; private Streichstadt; Final Int Code = 0x717; @Override Protected void OnCreate (Bündel SavedInstancestate) {Super.oncreate (SavedInstancestate); setContentView (r.layout.Activity_main); enden = (button) findViewById (r.id.submit); setSetonClickListener (neue Ansicht. repwd = (editText) findViewById (R.Id.Repwd)). GetText (). ToString (); i = 0; i <sex.getChildCount (); i ++) {Radiobutton r = (Radiobutton). Spinner.SetonItemSelectedIleNer (neuer adapterView.onitemSelectedListener () {@Override public void onitemSelected (adapterview <?> übergeordnete Ansicht, int Position, Long id) {City = Parentitematposition (Position) .TostRing (); }); ", Toast.length_long) .show (); ((editText) findViewById (r.id.pwd)). SetText (" "); ((editText) findViewById (r.id.id.Repwd)). SetText (" "); Intent (MainActivity.Dis, Registeracivity.class); Intent.putExtras (Bündel); 4. Registeracivity.java
paket com.example.ejcker_llin.myapplication; importieren android.app.Activity; import android.content.intent; import android.os.bundle; importieren Sie Android.view.view; importieren Sie Android.widget.button; importieren Sie Android.widget.textView; /*** Erstellt von jcker_llin am 2016/4/5. */public class Registeracivity erweitert die Aktivität {@Override geschütztes void OnCreate (Bündel SavedInstancestate) {Super.oncreate (SavedInstancestate); setContentView (R.Layout.register); endgültige Absicht intent = getIntent (); Bündel bündel = intent.getExtras (); TextView user = (textView) findViewById (R.Id.User); user.setText ("Benutzername:"+bündel.getString ("Benutzer")); TextView sex = (textView) findViewById (R.Id.sex); sex.setText ("Geschlecht:"+bündel.getString ("Sex")); TextView city = (textView) findViewById (R.Id.City); City.SetText ("Stadt:"+bündel.getString ("Stadt"); TextView pwd = (textView) findViewById (R.Id.pwd); pwd.setText ("Passwort:"+bündel.getString ("pwd")); TextView mail = (textView) findViewById (R.Id.Email); E-Mail.setText ("E-Mail:"+bündel.getString ("E-Mail")); Schaltfläche Schaltfläche = (Schaltfläche) findViewById (R.Id.back); button.setonclickListener (neue Ansicht. }}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> <Etil> xi'an </item> <element> Andere </item> </string-array> </ressourcen>
Das Obige dreht sich alles um diesen Artikel, ich hoffe, es wird für das Lernen aller hilfreich sein.