点击确定:

点击修改:

 

 

想到Spinner下拉按钮可以通过两种方法生成

方法一:

1、在array数组里面定义数组

代码如下:

<resources>
    <st
<?xml version="1.0" encoding="utf-8"?>
ring-array name="balls">
        <item >篮球</item>
        <item >足球</item>
        <item >网球</item>
        <item >排球</item>
    </string-array>
    
        <string-array name="citys">
        <item >北京</item>
        <item >上海</item>
        <item >大连</item>
        <item >合肥</item>
         <item >安徽</item>
    </string-array>
    
</resources>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

2、在spinner布局下,将数组应用过来

     代码如下:

   <Spinner
       android:id="@+id/spinner"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_toRightOf="@+id/city"
       android:entries="@array/citys"
       android:prompt="@string/city" />

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

3、再在.java中定义声明,然后用其本身的方法获得其值

代码如下:

private Spinner citySpinner;
citySpinner = (Spinner)findViewById(R.id.spinner);
 
    //从spinner 下拉框中获取选择的值
protected String getCitys() {
        // TODO Auto-generated method stub
     return citySpinner.getSelectedItem().toString();
    }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

方法二:

1、在Spinner的布局文件里面先定义,但不要有值。

<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/city"
android:id="@+id/cityItems">
</Spinner>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

2、定义数组和Spinner

private static final String[] cities = { "北京", "上海", "广州", "郑州" };

private Spinner cityItems;

3、将定义的Spinne与布局文件中的id挂钩

cityItems = (Spinner) findViewById(R.id.cityItems);

4、创建一个数组型适配器并将cities中的数据与系统默认的spinner布局文件中的元素挂钩

ArrayAdapter<String> adpter = new ArrayAdapter<String>(

LoginActivity.this,android.R.layout.simple_spinner_item,cities);

5、将此适配器adpter设置为setdropdownviewresource的模式

(Sets the layout resource to create the drop down views)

adpter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

6、将文件中定义的Spinner与适配器建立联系

cityItems.setAdapter(adpter);

  private    String[]   cityItems;
setContentView(R.layout.main);
        
Spinner spinner = (Spinner) findViewById(R.id.cityItems);
        
cityItems = getResources().getStringArray(R.array.citys);
ArrayAdapter< String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item,cityItems);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Toast.makeText(MainActivity.this, "您选择的是"+ spinner.getSelectedItem().toString(), 2000).show();

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

废话不多说,直接贴源码

String.xml当中的源码

<?xml version="1.0" encoding="utf-8"?>
<resources>
 
    <string name="app_name">Login</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="user">用户名:</string>
    <string name="secret">密码:</string>
    <string name="age">年龄:</string>
    <string name="sex">性别:</string>
    <string name="hobby">喜好:</string>
    <string name="woman">女</string>
    <string name="man">男</string>
    <string name="city">城市:</string>
    <string name="football">足球</string>
    <string name="basketball">篮球</string>
    <string name="pingpong">乒乓球</string>
    <string name="ski">滑冰</string>
    <string name="submit">注册</string>
 
</resources>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Arrays.xml当中的源码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <string-array name="citys">
        <item >北京</item>
        <item >上海</item>
        <item >大连</item>
        <item >合肥</item>
         <item >安徽</item>
    </string-array>
</resources>




.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Dimen.xml当中的源码:(主要用于规定字符的大小,文本框的尺寸等)

<resources>
 
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="fontsize">30px</dimen>
    <dimen name="TextViewWidth">120px</dimen>
    <dimen name="EditTextWidth">220px</dimen>
</resources>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

main.xml当中的布局文件

   1:  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   2:      xmlns:tools="http://schemas.android.com/tools"
   3:      android:layout_width="fill_parent"
   4:      android:layout_height="fill_parent"
   5:      android:orientation="vertical" 
   6:      tools:context=".MainActivity" >
   7:   
   8:      <RelativeLayout 
   9:         android:layout_width="fill_parent"
  10:         android:layout_height="wrap_content"  
  11:          >
  12:      <TextView
  13:          android:id="@+id/name"
  14:          android:layout_width="@dimen/TextViewWidth"
  15:          android:layout_height="wrap_content"
  16:          android:layout_alignParentLeft="true"
  17:          android:layout_centerVertical="true"
  18:          android:text="@string/user"
  19:          android:textSize="@dimen/fontsize" />
  20:      <EditText
  21:          android:layout_width="@dimen/EditTextWidth"
  22:          android:layout_height="wrap_content"
  23:          android:layout_alignParentRight="true"
  24:          android:layout_alignTop="@id/name"
  25:          android:hint="zhuxuekui"
  26:          android:id="@+id/nameValue"
  27:          />
  28:     </RelativeLayout>
  29:     
  30:      
  31:      
  32:      <RelativeLayout 
  33:         android:layout_width="fill_parent"
  34:         android:layout_height="wrap_content"  
  35:          >
  36:      <TextView
  37:          android:id="@+id/secret1"
  38:          android:layout_width="@dimen/TextViewWidth"
  39:          android:layout_height="wrap_content"
  40:          android:layout_alignParentLeft="true"
  41:          android:layout_centerVertical="true"
  42:          android:text="@string/secret"
  43:          android:textSize="@dimen/fontsize" />
  44:   
  45:      <EditText
  46:          android:id="@+id/secret"
  47:          android:layout_width="@dimen/EditTextWidth"
  48:          android:layout_height="wrap_content"
  49:          android:layout_alignParentRight="true"
  50:          android:layout_alignParentTop="true"
  51:          android:ems="10"
  52:          android:hint="123456" >
  53:      </EditText>
  54:     </RelativeLayout>
  55:     
  56:      
  57:     <RelativeLayout 
  58:         android:layout_width="fill_parent"
  59:         android:layout_height="wrap_content"  
  60:          >
  61:      <TextView
  62:          android:id="@+id/age1"
  63:          android:layout_width="@dimen/TextViewWidth"
  64:          android:layout_height="wrap_content"
  65:          android:layout_alignParentLeft="true"
  66:          android:layout_centerVertical="true"
  67:          android:text="@string/age"
  68:          android:textSize="@dimen/fontsize" />
  69:   
  70:      <EditText
  71:          android:id="@+id/age"
  72:          android:layout_width="@dimen/EditTextWidth"
  73:          android:layout_height="wrap_content"
  74:          android:layout_alignParentRight="true"
  75:          android:layout_alignParentTop="true"
  76:          android:ems="10"
  77:          android:hint="20 ">
  78:      </EditText>
  79:     </RelativeLayout>
  80:     
  81:     <RelativeLayout
  82:         android:layout_width="238dp"
  83:         android:layout_height="wrap_content" >
  84:  <TextView
  85:          android:id="@+id/sex"
  86:          android:layout_width="@dimen/TextViewWidth"
  87:          android:layout_height="wrap_content"
  88:          android:layout_alignParentLeft="true"
  89:          android:layout_alignParentTop="true"
  90:          android:layout_marginTop="17dp"
  91:          android:text="@string/sex"
  92:          android:textSize="@dimen/fontsize" />
  93:      <RadioGroup
  94:          android:id="@+id/sex2"
  95:          android:layout_width="wrap_content"
  96:          android:layout_height="wrap_content"
  97:          android:layout_toRightOf="@id/sex"
  98:          android:checkedButton="@+id/woman"
  99:          android:orientation="horizontal" >
 100:   
 101:         <RadioButton
 102:           android:text="@string/man"
 103:           android:id="@+id/man"
 104:          />  
 105:          <RadioButton
 106:           android:text="@string/woman"
 107:           android:id="@+id/woman"
 108:          />    
 109:      </RadioGroup>
 110:     </RelativeLayout>
 111:     
 112:     
 113:         <RelativeLayout 
 114:         android:layout_width="fill_parent"
 115:         android:layout_height="wrap_content"  
 116:          >
 117:      <TextView
 118:          android:id="@+id/city"
 119:          android:layout_width="@dimen/TextViewWidth"
 120:          android:layout_height="wrap_content"
 121:          android:layout_alignParentLeft="true"
 122:          android:layout_centerVertical="true"
 123:          android:text="@string/city"
 124:          android:textSize="@dimen/fontsize" />
 125:   
 126:     <Spinner
 127:         android:id="@+id/spinner"
 128:         android:layout_width="wrap_content"
 129:         android:layout_height="wrap_content"
 130:         android:layout_toRightOf="@+id/city"
 131:         android:entries="@array/citys"
 132:         android:prompt="@string/city" />
 133:   
 134:     </RelativeLayout>
 135:     
 136:         
 137:         <RelativeLayout 
 138:         android:layout_width="fill_parent"
 139:         android:layout_height="wrap_content"  
 140:          >
 141:      <TextView
 142:          android:id="@+id/hobby"
 143:          android:layout_width="@dimen/TextViewWidth"
 144:          android:layout_height="wrap_content"
 145:          android:layout_alignParentLeft="true"
 146:          android:layout_centerVertical="true"
 147:          android:text="@string/hobby"
 148:          android:textSize="@dimen/fontsize" />
 149:   
 150:      <CheckBox
 151:          android:id="@+id/football"
 152:          android:layout_width="wrap_content"
 153:          android:layout_height="wrap_content"
 154:          android:layout_alignParentTop="true"
 155:          android:layout_toRightOf="@+id/hobby"
 156:          android:text="@string/football" />
 157:      
 158:   
 159:              <CheckBox
 160:                  android:id="@+id/pingpong"
 161:                  android:layout_width="wrap_content"
 162:                  android:layout_height="wrap_content"
 163:                  android:layout_alignLeft="@+id/football"
 164:                  android:layout_below="@+id/football"
 165:                  android:text="@string/pingpong" />
 166:              
 167:   
 168:   
 169:               <CheckBox
 170:                   android:id="@+id/basketball"
 171:                   android:layout_width="wrap_content"
 172:                   android:layout_height="wrap_content"
 173:                   android:layout_alignParentTop="true"
 174:                   android:layout_toRightOf="@+id/pingpong"
 175:                   android:text="@string/basketball" />
 176:               
 177:               <CheckBox
 178:                   android:id="@+id/ski"
 179:                   android:layout_width="wrap_content"
 180:                   android:layout_height="wrap_content"
 181:                   android:layout_below="@id/basketball"
 182:                   android:layout_toRightOf="@+id/pingpong"
 183:                   android:text="@string/ski" />
 184:   
 185:     </RelativeLayout>
 186:  <Button 
 187:      android:layout_width="wrap_content"
 188:      android:layout_height="wrap_content"
 189:      android:id="@+id/submit"
 190:      android:text="@string/submit"
 191:      android:textSize="@dimen/fontsize"
 192:      
 193:      />
 194:   
 195:     
 196:  </LinearLayout>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

MainAcitivity.java当中的源码:

   1:  package com.example.login;
   2:   
   3:  import java.util.ArrayList;
   4:  import java.util.List;
   5:   
   6:  import android.R.string;
   7:  import android.os.Bundle;
   8:  import android.app.Activity;
   9:  import android.app.AlertDialog;
  10:  import android.app.ProgressDialog;
  11:  import android.content.DialogInterface;
  12:  import android.view.Menu;
  13:  import android.view.View;
  14:  import android.view.ViewGroup;
  15:  import android.widget.ArrayAdapter;
  16:  import android.widget.Button;
  17:  import android.widget.CheckBox;
  18:  import android.widget.EditText;
  19:  import android.widget.RadioButton;
  20:  import android.widget.RadioGroup;
  21:  import android.widget.Spinner;
  22:   
  23:  public class MainActivity extends Activity {
  24:      
  25:      private EditText name,age,pass;
  26:      private Button regButton;
  27:      private RadioGroup sexRadioGroup;
  28:      private CheckBox basketball,pingpong,football,ski;
  29:      private Spinner citySpinner;
  30:      private List<CheckBox> myhobbysBoxs;
  31:  //    private String[]  cityarray;
  32:      
  33:      private boolean flag = true;
  34:      
  35:      @Override
  36:      protected void onCreate(Bundle savedInstanceState) {
  37:          super.onCreate(savedInstanceState);
  38:          setContentView(R.layout.activity_main);
  39:          //定义一个ArrayList( ) 用来存放所有的checkbox
  40:           myhobbysBoxs = new  ArrayList<CheckBox>();
  41:           
  42:          //得到相应的显示控件的对象
  43:           name = (EditText)findViewById(R.id.nameValue);
  44:           age = (EditText)findViewById(R.id.age);
  45:           pass = (EditText)findViewById(R.id.secret);
  46:           regButton = (Button)findViewById(R.id.submit);
  47:           
  48:           //获取单选框的控件,注意一小点,静态的文件与输入的文本框的id不可以重复
  49:           sexRadioGroup = (RadioGroup)findViewById(R.id.sex2);
  50:           
  51:           //获取多选框的的id并将他们当中的每一个小项放入List<CheckBox> 这样的checkbox类型的List容器中。
  52:           basketball = (CheckBox)findViewById(R.id.basketball);
  53:           myhobbysBoxs.add(basketball);
  54:           pingpong = (CheckBox)findViewById(R.id.pingpong);
  55:           myhobbysBoxs.add(pingpong);
  56:           football = (CheckBox)findViewById(R.id.football);
  57:           myhobbysBoxs.add(football);
  58:           ski = (CheckBox)findViewById(R.id.ski);
  59:           myhobbysBoxs.add(ski);
  60:           
  61:           //获取spinner中的id
  62:           citySpinner = (Spinner)findViewById(R.id.spinner);
  63:           //这是第二种 在.java中显示spinner布局框中的项方法
  64:          //cityarray = getResources().getStringArray(R.array.citys);
  65:          
  66:          //ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, cityarray);
  67:           
  68:           //创建按钮监听事件
  69:           regButton.setOnClickListener(new  View.OnClickListener() {
  70:              //AlertDialog警告对话框,我们可以设置对话框的
  71:              @Override
  72:              public void onClick(View v) {
  73:                  // TODO Auto-generated method stub
  74:                  flag =  addUser();
  75:                  if(flag)
  76:                  {
  77:                      //创建一个 AlertDialog 类的内部类 Builder 的对象
  78:                      AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  79:                      //为 builer 设置标题
  80:                      builder.setTitle("请确认信息")
  81:                      //为 builer 设置消息内容
  82:                        .setMessage("您的信息如下:"+ "\n" 
  83:                              + "姓名:"+ name.getText().toString() + "\n" + "年龄:" + age.getText().toString() + "\n" + "性别:" + getSex() + "\n" 
  84:                              + "爱好:" + getHobby() + "\n" + "城市:" + getCitys() + "\n")
  85:                      //设置为 false 后,键盘上的后退键失效,默认为ture,也就是说必须按下警告键,后退键无效,所以设置为false
  86:                       .setCancelable(false)
  87:                       //添 加 确 定 按 钮 , 并 添 加 对 该 按 钮 的 处 理 事 件 
  88:                       .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  89:                                  
  90:                                  @Override
  91:                                  public void onClick(DialogInterface dialog, int which) {
  92:                                      // TODO Auto-generated method stub
  93:                                      //进度条,有点像圆形进度条,progressbar。 后面那句说明,现在返回键有效。
  94:                                      ProgressDialog.show(MainActivity.this, "用户信息注册中", "请等待.......").setCancelable(true);
  95:                                      }
  96:                                    }
  97:                                  )
  98:                      .setNegativeButton("修改", new DialogInterface.OnClickListener() {
  99:                                  
 100:                                  @Override
 101:                                  public void onClick(DialogInterface dialog, int which) {
 102:                                      // TODO Auto-generated method stub
 103:                                       dialog.cancel();//删除对话框
 104:                                    }
 105:                               });
 106:                      AlertDialog alertDialog = builder.show();//显示对话框
 107:                  }
 108:                      
 109:                      
 110:                      //创建一个AlertDialog对话框显示登录的信息,这个方法中他会有一个确认的过程,点击确定需要干嘛干嘛,点击取消需要干嘛干嘛
 111:  //                    new AlertDialog.Builder(MainActivity.this).setTitle("请确认信息").setMessage("您的信息如下:"+ "\n" 
 112:  //                            + "姓名:"+ name.getText().toString() + "\n" + "年龄:" + age.getText().toString() + "\n" + "性别:" + getSex() + "\n" 
 113:  //                            + "爱好:" + getHobby() + "\n" + "城市:" + getCitys() + "\n").setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
 114:  //                                
 115:  //                                @Override
 116:  //                                public void onClick(DialogInterface dialog, int which) {
 117:  //                                    // TODO Auto-generated method stub
 118:  //                                    //进度条
 119:  //                                    ProgressDialog.show(MainActivity.this, "用户信息注册中", "请等待.......").setCancelable(true);
 120:  //                                }
 121:  //                            }
 122:  //                            ).setNegativeButton("修改", new DialogInterface.OnClickListener() {
 123:  //                                
 124:  //                                @Override
 125:  //                                public void onClick(DialogInterface dialog, int which) {
 126:  //                                    // TODO Auto-generated method stub
 127:  //                                     dialog.cancel();//删除对话框
 128:  //                                }
 129:  //                            }).show();     //显示对话框
 130:              }
 131:   
 132:          });
 133:      }
 134:      //从spinner 下拉列表框中获取选择的值
 135:   protected String getCitys() {
 136:          // TODO Auto-generated method stub
 137:        return citySpinner.getSelectedItem().toString();
 138:      }
 139:  //从多选框中获取字符串并返回
 140:      protected String getHobby() {
 141:          // TODO Auto-generated method stub
 142:          //采用一直轮询机制,从1到结束。这种for结构很有趣,然后选择一个加”“。
 143:          String fasString = "";
 144:         for (CheckBox cBox : myhobbysBoxs) {
 145:          if(cBox.isChecked())
 146:          {
 147:              fasString += cBox.getText().toString();
 148:              fasString += ",";
 149:          }
 150:         }
 151:          //substring(int beginIndex, int endIndex)  返回一个新字符串,它是此字符串的一个子字符串。
 152:          if(fasString != "")
 153:          {
 154:              fasString = fasString.substring(0, fasString.length() - 1);
 155:          }
 156:          else {
 157:              fasString = "您没有选择爱好!";
 158:          }
 159:          return  fasString;
 160:      }
 161:  //从单选框中获取字符串并返回
 162:      protected String getSex() {
 163:          // TODO Auto-generated method stub
 164:          RadioButton mButton = (RadioButton)findViewById(sexRadioGroup.getCheckedRadioButtonId());
 165:          return mButton.getText().toString();
 166:      }
 167:   
 168:      //验证输入是否合法
 169:      protected boolean addUser() {
 170:          // TODO Auto-generated method stub
 171:          if (name.getText().toString().length() == 0) {
 172:              name.setError("用户名不能为空");  //在view上的效果是,会出现!号。
 173:              return false;    
 174:          }
 175:          if (age.getText().toString().length() == 0) {
 176:              age.setError("年龄不能为空");
 177:              return false;    
 178:          }
 179:          if (pass.getText().toString().length() == 0) {
 180:              pass.setError("密码不能为空");
 181:              return false;    
 182:          }
 183:          return true;    
 184:      }
 185:   
 186:      @Override
 187:      public boolean onCreateOptionsMenu(Menu menu) {
 188:          // Inflate the menu; this adds items to the action bar if it is present.
 189:          getMenuInflater().inflate(R.menu.main, menu);
 190:          return true;
 191:      }
 192:   
 193:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 

登陆界面综合实例+spinner下拉列表框详解的更多相关文章

  1. mybatis中的mapper接口文件以及example类的实例函数以及详解

    ##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列 ...

  2. 实例-sprintf() 函数详解-输出格式转换函数

    Part1:实例 $filterfile = basename(PHP_SELF, '.php'); if (isset($_GET['uselastfilter']) && isse ...

  3. curl库pycurl实例及参数详解

    pycurl是功能强大的python的url库,是用c语言写的,速度很快,比urllib和httplib都快. 今天我们来看一下pycurl的用法及参数详解 常用方法: pycurl.Curl() # ...

  4. Android Developer -- Bluetooth篇 开发实例之四 API详解

    http://www.open-open.com/lib/view/open1390879771695.html 这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每 ...

  5. azkaban web ui界面出现异常诡异“丑”界面的问题解决(图文详解)

    前期博客 启动azkaban时出现User xml file conf/azkaban-users.xml doesn't exist问题解决(图文详解) 问题详情 [hadoop@master co ...

  6. vue实例生命周期详解

    每个 Vue 实例在被创建之前都要经过一系列的初始化过程. 例如,实例需要配置数据观测(data observer).编译模版.挂载实例到 DOM ,然后在数据变化时更新 DOM . 在这个过程中,实 ...

  7. UWP开发之Mvvmlight实践三:简单MVVM实例开发(图文详解付代码)

    在做MVVM各种框架对比之前,我觉得有必要先自己做一个简单的MVVM实现案例比较好,这样就可以看到自己实现的时候有那些不方便的地方.而各种框架又是怎么解决我们这些麻烦的. 案例介绍:用户登录画面,没有 ...

  8. ios 利用Reveal来调试界面1 --模拟器(步骤详解)

    Reveal是一个程序界面调试工具,可以调试iOS apps和tvOS apps.使用Reveal,我们可以在开发时动态地查看和修改应用程序的界面.避免每次修改UI的时候都要重新运行程序.接下来按照规 ...

  9. ThinkPHP第十四天(显示TRACE界面配置,关联模型详解定义)

    1.显示TRACE界面,首选需要在显示模版界面,$this->display(),然后需要在配置文件中配置 SHOW_PAGE_TRACE => true 2.关联模型使用 主表以user ...

随机推荐

  1. 【bzoj2132】圈地计划 网络流最小割

    题目描述 最近房地产商GDOI(Group of Dumbbells Or Idiots)从NOI(Nuts Old Idiots)手中得到了一块开发土地.据了解,这块土地是一块矩形的区域,可以纵横划 ...

  2. 【bzoj4896】[Thu Summer Camp2016]补退选 Trie树+STL-vector

    题目描述 X是T大的一名老师,每年他都要教授许多学生基础的C++知识.在T大,每个学生在每学期的开学前都需要选课,每次选课一共分为三个阶段:预选,正选,补退选:其中"补退选"阶段最 ...

  3. HDU 3622 Bomb Game(二分+2-SAT)

    Bomb Game Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. webRTC前世今生

    WebRTC 的前世今生 本文由 rwebrtc 翻译 WebRTC 技术是激烈的开放的 Web 战争中一大突破.-Brendan Eich, inventor of JavaScript 无插件实时 ...

  5. Python 读取 pkl文件

    使用python 的cPickle 库中的load函数,可以读取pkl文件的内容 import cPickle as pickle fr = open('mnist.pkl') #open的参数是pk ...

  6. vue基础教程

    1.执行npm install 2.安装stylus,(npm install之后node_module已经有了stylus,但还是要再安装一次) npm install --save-dev sty ...

  7. Python之数据结构:集合

    一.set集合 1.集合是一个无序不重复元素集,有去重的作用 set集合类需要的参数必须是迭代器类型的,如:序列.字典等,然后转换成无序不重复的元素集.由于集合是不重复的,所以可以对字符串.列表.元组 ...

  8. JS与验证控件结合验证

    原文发布时间为:2010-05-14 -- 来源于本人的百度文章 [由搬家工具导入] 把BUTTOn中 的return CheckFive()去 掉 .. 放 到 <Form id=" ...

  9. android基本控件学习-----ProgressBar

    ProgressBar(进度条)讲解 一.常用属性和基础使用实例 (1)常用属性: android:max:进度条的最大值 android:progress:进度条已完成进度值 android:pro ...

  10. 一个.java文件定义多个类的情况

    一个.java文件中定义多个类: 注意一下几点: (1) public权限类只能有一个(也可以一个都没有,但最多只有一个): (2)这个.java文件名只能是public 权限的类的类名: (3)倘若 ...