一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - java實現簡單注冊選擇所在城市

java實現簡單注冊選擇所在城市

2020-04-16 13:51格子里的眼眶 JAVA教程

這篇文章主要為大家詳細介紹了java實現簡單注冊選擇所在城市的相關代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

1.activity_main.xml    

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?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 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?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    

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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  

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.

java實現簡單注冊選擇所在城市

6.

java實現簡單注冊選擇所在城市

7. arrays.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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>

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 1986葫芦兄弟全集免费观看第十集 | 亚洲成年人免费网站 | 我和岳偷长篇小说 | 亚洲欧美另类在线观看 | 欧美 国产 日韩 第一页 | 国产亚洲精品一区二区在线观看 | 男人的天堂视频 | 精品视频国产 | 明星ai人脸替换造梦在线播放 | 国产成人综合一区人人 | 无码中文字幕热热久久 | 亚洲色图色 | 精品久久久麻豆国产精品 | 亚洲成年网站在线观看 | 99在线精品免费视频 | 青青草99久久精品国产综合 | 小苹果日本在线观看 | 男公厕里同性做爰 | 拔插拔插8x8x海外华人免费视频 | 国产精品一区二区不卡的视频 | 国产区久久 | 亚洲欧美另类专区 | 亚洲精品123区在线观看 | 国产高清露脸学生在线观看 | free嫩白的12sex性自由 | 激情婷婷综合久久久久 | 99热久久国产精品这里 | 99久久国产综合精品女不卡 | 国产清纯女高中生在线观看 | 精品久久久久久亚洲 | 手机看片自拍自自拍日韩免费 | 2022最新a精品视频在线观看 | 国产成人亚洲综合网站不卡 | 亚洲黑人巨大videos0 | 欧美日韩在线观看区一二 | 天生奶水1v1高h | 亚洲精品黄色 | 亚洲电影成人 成人影院 | 日本高清免费不卡在线播放 | 国产一区二区三区免费在线视频 | 色欲麻将|