Os exemplos deste artigo compartilham todos os códigos para o Java implementar o registro simples e selecionar a cidade em que estão localizados para sua referência. O conteúdo específico é o seguinte
1.Activity_Main.xml
<? xml versão = "1.0" coding = "utf-8"?> <linearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: ferramentas = "http://schemas.android.com/ools.ools.ools"/" Android: layout_width = "FILL_PARENT" Android: Layout_Height = "FILL_PARENT"> <TextView Android: layout_width = "wrap_content" Android: Layout_Height = "Wrap_content" Android: "Username:" /> <DITTEXT Andro) Android: minwidth = "200px" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> <linearLayout Android: gravity = "Center_vertical" Android: Layout_width = "Match_Parent" Android: 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 = "Woman"/> </Radiogroup> </linearLayout> <linearlayout Android: Orientation = "Vertical" Android: layout_width = WRAYOUT_CR_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_CT_C "WRAPT_CT_CT_CT_CT_CT_CENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTENTET_CETHET_CT = Android) <TextView Android: id = "@+id/textView1" Android: text = "Por favor, selecione sua cidade:" Android: layout_height = "wrap_content" Android: layout_width = "wrap_content"/> <spinner Android: ARTIES = "@Array/ctype" Andriid: Android: Android: "@"@prAray/ctys) Android: layout_width = "wrap_content" Android: id = "@+id/spinner1"/> </linearlayout> <textView Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" android: text = " Android: MinWidth = "200px" Android: inputType = "TextPassword" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" /> <textView Android: Layout_width = "WRAP_CONTENT" Android: Senha: " /> <edittExt Android: id ="@+id /repwd "Android: minwidth =" 200px "Android: inputType =" textpassword "Android: Layout_width =" wrap_content "Android: Layout_Height =" Wrap_Content " /> android:layout_width="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" /> <botão Android: id = "@+id /submit" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "submit" /> < /linearlayout>
2.Register.xml
<? xml versão = "1.0" coding = "utf-8"?> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" andro: layout_height_height = " Android: layout_height = "wrap_content" Android: Padding = "10px" Android: text = "Nome de usuário:" /> <TextView Android: id = "@+id /sexo" Android: Layout_width = "Wrap_content": Android: Layout_Height = "WRAP_CRAT_CONTENTEN" Android: text = "Gênero:" /> <TextView Android: id = "@+id /city" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Padding = "10px" Android: text = "City:" /> <TextRoid Android: Android: "10px" Android = "TEXT =": " /> <TextRoid" Android: Android: "10px" Android = "City:" /> <Text " Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Padding = "10px" Android: text = "senha:" /> <TextView Android: ID = "@ID /Email" Android: "10px" Android: Android: "@+id /email" Android: "10px" Android: Android: layout_height = "wrap_content" Android: text = "E-mail:" /> <Button Android: id = "@+id /back" Android: text = "Voltar para a etapa anterior" Android: Layout_width = "Wrap_content" Android: Layout_Height = "WRAP_CONTELE
3. MainActivity.Java
pacote com.example.ejcker_llin.myApplication; importar Android.App.Activity; importar Android.Content.Intent; importar Android.support.v7.app.appCompatactivity; importar Android.os.bundle; importação Android.View.View; importação Android.widget.adapterview; imported.widget.button; importroid.widget.adapterview; importview; Android.widget.radiobutton; importar Android.widget.radiogroup; importar Android.widget.spinner; importar Android.widget.toast; classe pública MainActivity estende a atividade {Botão privado envie; String private sexo1; Private String City; Código INT final = 0x717; @Override Protected void onCreate (pacote savedInstancestate) {super.oCreate (savedInstancestate); setContentView (r.layout.activity_main); enviar = (botão) findViewById (r.id.submit); submit.setOnClickListener (new View.OnClickListener () {@Override public void OnClick (View V) {String user = ((edittExt) findViewbyId (r.id.User)). getText () .pwring (); string pwd = (editText)). Repwd = (EdittExt) FindViewbyId (r.id.repwd)). getText (). ToString (); i = 0; i <sex.getchildcount (); i ++) {radiobutton r = (radiobutton) Sex.getChildat (i); Adapterview.onItemSelectedListener () {@Override public void oniTemSelected (Adapterview <? if (! "". Equals (usuário) &&! "". Equals (PWD) &&! "". Equals (email)) {if (! ", Toast.Length_long) .Show (); (((edittExt) findViewById (r.id.pwd)). SetText (" "); (((edittExt) findViewId (r.id.repwd). SetText (" "); (edittExt)). Intent (MainActivy.This, Registeracivy.class); Intent.Putextras (pacote); 4. Registeracivity.java
pacote com.example.ejcker_llin.myApplication; importar Android.App.Activity; importar Android.Content.Intent; importar Android.os.bundle; importar Android.View.View; importar Android.widget.button; importar Android.widget.textview; /*** Criado por JCKer_llin em 2016/4/5. */classe pública Registeracivity estende a atividade {@Override Protected Void OnCreate (pacote savedInstancestate) {super.oCreate (savedInstancestate); setContentView (r.layout.register); intenção final intenção = getIntent (); Pacote de pacote = intent.getextras (); Textview user = (textview) findViewById (r.id.User); user.settext ("Nome de usuário:"+bundle.getString ("user")); TextView Sex = (TextView) FindViewById (R.id.Sex); sex.settext ("gênero:"+pacote.getString ("sexo")); TextView City = (TextView) FindViewById (r.id.city); City.Settext ("City:"+Bundle.getString ("City")); TextView pwd = (textView) findViewById (r.id.pwd); pwd.settext ("senha:"+bundle.getString ("pwd")); TextView email = (TextView) FindViewById (R.id.Email); email.settext ("E-mail:"+bundle.getString ("email")); Botão botão = (botão) findViewById (r.id.back); Button.SetOnClickListener (new View.OnClickListener () {@Override public void OnClick (View V) {setResult (0x717, intenção); finalize ();}}); }}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> <tem> xi'an </tem> <tem> Outros </tem> </string-array> </recursos>
O exposto acima é tudo sobre este artigo, espero que seja útil para o aprendizado de todos.