欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java實現(xiàn)簡單注冊選擇所在城市

 更新時間:2016年04月06日 15:20:32   作者:格子里的眼眶  
這篇文章主要為大家詳細介紹了java實現(xiàn)簡單注冊選擇所在城市的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現(xiàn)簡單注冊選擇所在城市的全部代碼,供大家參考,具體內(nèi)容如下

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_height="wrap_content"
  android:text="用戶名:"
  />
 <EditText
  android:id="@+id/user"
  android:minWidth="200px"
  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="性別:"
   />
  <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="男"/>
   <RadioButton
    android:id="@+id/radio1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="女"/>
  </RadioGroup>
 </LinearLayout>
<LinearLayout
 android:orientation="vertical"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
 <TextView android:id="@+id/textView1"
  android:text="請選擇所在城市:"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"/>
 <Spinner
  android:entries="@array/ctype"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:id="@+id/spinner1"/>
</LinearLayout>
 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="密碼:"/>
 <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="確認密碼:"
  />
 <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地址:" />
 
 <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"
  android:text="提交" />
 
 
</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="用戶名:" />
 <TextView
  android:id="@+id/sex"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:padding="10px"
  android:text="性別:"
  />
 <TextView
  android:id="@+id/city"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:padding="10px"
  android:text="城市:"
  />
 
 <TextView
  android:id="@+id/pwd"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:padding="10px"
  android:text="密碼:" />
 
 <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/back"
  android:text="返回上一步"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />
 
</LinearLayout>

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=((EditText)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 onItemSelected(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,"兩次輸入的密碼不一致,請重新輸入!",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,"請將注冊信息輸入完整!",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("用戶名:"+bundle.getString("user"));
  TextView sex= (TextView) findViewById(R.id.sex);
  sex.setText("性別:"+bundle.getString("sex"));
  TextView city= (TextView) findViewById(R.id.city);
  city.setText("城市:"+bundle.getString("city"));
  TextView pwd= (TextView) findViewById(R.id.pwd);
  pwd.setText("密碼:"+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,intent);
    finish();
 
   }
  });
 }
}

5.

6.

7. arrays.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string-array name="ctype">
  <item>北京</item>
  <item>上海</item>
  <item>廣州</item>
  <item>杭州</item>
  <item>天津</item>
  <item>香港</item>
  <item>重慶</item>
  <item>西安</item>
  <item>其他</item>
 </string-array>
</resources>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。

相關(guān)文章

  • Spring中的@EnableScheduling定時任務(wù)注解

    Spring中的@EnableScheduling定時任務(wù)注解

    這篇文章主要介紹了Spring中的@EnableScheduling注解,@EnableScheduling是 Spring Framework 提供的一個注解,用于啟用 Spring 的定時任務(wù)功能,通過使用這個注解,可以在 Spring 應用程序中創(chuàng)建定時任務(wù),需要的朋友可以參考下
    2024-01-01
  • Java 最優(yōu)二叉樹的哈夫曼算法的簡單實現(xiàn)

    Java 最優(yōu)二叉樹的哈夫曼算法的簡單實現(xiàn)

    這篇文章主要介紹了Java 最優(yōu)二叉樹的哈夫曼算法的簡單實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • 一文搞懂Java項目中枚舉的定義與使用

    一文搞懂Java項目中枚舉的定義與使用

    枚舉就是用enum修飾是一種Java特殊的類,枚舉是class、底層是繼承了java.lang.Enum類的實體類。本文將詳解枚舉的定義與使用,需要的可以參考一下
    2022-06-06
  • SpringBoot中的Logging詳解

    SpringBoot中的Logging詳解

    這篇文章主要介紹了SpringBoot中的Logging詳解,log配置可能是被忽視的一個環(huán)節(jié),一般的項目中日志配置好了基本上很少去改動,我們常規(guī)操作是log.info來記錄日志內(nèi)容,很少會有人注意到springBoot中日志的配置,需要的朋友可以參考下
    2023-09-09
  • Spring Boot整合tk.mybatis代碼實例

    Spring Boot整合tk.mybatis代碼實例

    這篇文章主要介紹了Spring Boot整合tk.mybatis代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11
  • Java并發(fā)編程線程間通訊實現(xiàn)過程詳解

    Java并發(fā)編程線程間通訊實現(xiàn)過程詳解

    這篇文章主要介紹了Java并發(fā)編程線程間通訊實現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • Java實現(xiàn)NIO聊天室的示例代碼(群聊+私聊)

    Java實現(xiàn)NIO聊天室的示例代碼(群聊+私聊)

    這篇文章主要介紹了Java實現(xiàn)NIO聊天室的示例代碼(群聊+私聊),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05
  • springboot集成springsession如何實現(xiàn)分布式session共享

    springboot集成springsession如何實現(xiàn)分布式session共享

    這篇文章主要介紹了springboot集成springsession如何實現(xiàn)分布式session共享問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • 親手教你SpringBoot中的多數(shù)據(jù)源集成問題

    親手教你SpringBoot中的多數(shù)據(jù)源集成問題

    本文主要是介紹基于springboot的多數(shù)據(jù)源切換,輕量級的一種集成方案,對于小型的應用可以采用這種方案,我之前在項目中用到是因為簡單,便于擴展以及優(yōu)化,對SpringBoot多數(shù)據(jù)源集成問題感興趣的朋友一起看看吧
    2022-03-03
  • 詳解java 中的CAS與ABA

    詳解java 中的CAS與ABA

    這篇文章主要介紹了java 中的CAS與ABA的相關(guān)資料,幫助大家更好的理解和學習使用Java,感興趣的朋友可以了解下
    2021-05-05

最新評論