XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
<Spinner
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/spinner" />
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/spinner"
    android:layout_marginTop="20dp"
    android:id="@+id/selectSpinnerValue"
    android:text="获取下拉框的值"
    />
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/selectSpinnerValue"
    android:layout_marginTop="20dp"
    android:id="@+id/showSpinnerValue"
    />
</RelativeLayout>

Activity:

public class SpinnerActivity extends Activity implements OnClickListener{
   private String[] food={"炒面","凉面","炸酱面","打卤面","手擀面"};
   private TextView showSpinnerValue;
   private Spinner spinner;
   private String[] tel;
 public  void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.spinner);
        spinner=(Spinner)findViewById(R.id.spinner);
        showSpinnerValue=(TextView)findViewById(R.id.showSpinnerValue);
        findViewById(R.id.selectSpinnerValue).setOnClickListener(this);
        //从资源读取数据内容
        tel=getResources().getStringArray(R.array.phonenumber);
        //定义适配器
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(SpinnerActivity.this,
          android.R.layout.simple_spinner_dropdown_item, tel);
        //给控件设置适配器
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
   public void onItemSelected(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {
    showSpinnerValue.setText(food[arg2]);
   }
   @Override
   public void onNothingSelected(AdapterView<?> arg0) {
                showSpinnerValue.setText("");
   }
         
  });
 }

@Override
 public void onClick(View v) {
  switch(v.getId()){
  case R.id.selectSpinnerValue:
   int index=spinner.getSelectedItemPosition();
   Toast.makeText(this, food[index],Toast.LENGTH_LONG ).show();
   break;
   default:
    break;
  }
  
 }

}

android下拉框的更多相关文章

  1. RaidoGroup+RadioButton模拟android下拉框弹出List

    引用 <上面的Hello world!是居左的,但是下面的文字却怎么都不能靠边.试了各种方法都不行.最后,无意中给RadioButton添加一个backgroud属性即可:<RadioBu ...

  2. Android 自定义spinner下拉框实现的实现

    请支持原创:http://blog.csdn.NET/geniuseoe2012/article/details/8723702 说到Android下拉框spineer,框架中虽有现成的控件,但实际效 ...

  3. android+myeclipse+mysql下拉框数据绑定

    原创作品,允许转载,转载时请务必声明作者信息和本声明.http://www.cnblogs.com/zhu520/p/8027036.html 本人小白,那个大神看到有问题可指出,谢谢.... 一:我 ...

  4. Android自定义spinner下拉框实现的实现

    一:前言 本人参考博客:http://blog.csdn.net/jdsjlzx/article/details/41316417 最近在弄一个下拉框,发现Android自带的很难实现我的功能,于是去 ...

  5. android模仿58筛选下拉框(PopupWindow实现)

    前言:前几天用58同城APP找房子的时候,看到筛选下拉框蛮不错的,然后也有很多朋友需要实现这个功能,于是从网上下载了一个demo,在他的基础上进行修改,花了几个小时对他的代码进行修改,重构,封装.把一 ...

  6. Android 自定义spinner下拉框实现

    一:前言本人参考博客:http://blog.csdn.net/jdsjlzx/article/details/41316417 最近在弄一个下拉框,发现Android自带的很难实现我的功能,于是去网 ...

  7. Android 第三方开源下拉框:NiceSpinner

    Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框Spinner所提供的设计样式,而改用自定 ...

  8. Android实现三级联动下拉框 下拉列表spinner

    Android实现(省.市.县)三级联动下拉框 下拉列表spinner 转载请注明出处: http://www.goteny.com/articles/2013/11/46.html http://w ...

  9. 一分钟掌握Android spinner下拉框

    Android 自带的spinner下拉框控件是一个不错的系统控件.主要有两种实现方式: 1.静态的spinner 在res\values中加入一个city资源数组文件 2 <resources ...

随机推荐

  1. oracle执行计划之-表连接方式

    转载自:http://blog.csdn.net/tianlesoftware/article/details/5826546 在多表联合查询的时候,如果我们查看它的执行计划,就会发现里面有多表之间的 ...

  2. 代理模式(Proxy Pattern)

    一.引言 在软件开发过程中,有些对象有时候会由于网络或其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让代 ...

  3. Docker学习---ubuntu环境

    添加Docker的ATP仓库 sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sour ...

  4. Linux破解root密码

    实验环境                 虚拟机软件:VMware Workstation                 操作系统:Read Hat Enteprise 6.3      1.破解r ...

  5. 关于VS2010无法编译问题

    cvtres.exe 近来遇到无法编译问题,编译后debug之类文件全部为空,纠结好久才发现还是一个以前遇到解决过的问题...= = C:\Windows\Microsoft.NET\Framewor ...

  6. CentOS 7下源码安装MySQL 5.6

    本文转载,并非原创. 目录 准备工作 运行环境 确认你的安装版本 下载MySQL 安装MySQL 准备安装环境 编译和安装 配置MySQL 单实例配置 单实例配置方法 添加防火墙 启动MySQL 重启 ...

  7. RPC与hadoop

    rlgdj的这样的话,真正的实现类在Server端,客户端调用方法的时候,只能得到得到从Server端的返回值.看来接口中的抽象方法必须要有返回值啊.ps.右下角的Client端的main()中rpc ...

  8. 如何提高Linux操作系统的安全性 转自https://yq.aliyun.com/articles/24251?spm=5176.100239.blogcont24250.7.CfBYE9

    摘要: Linux系统不论在功能上.价格上或性能上都有很多优点,但作为开放式操作系统,它不可避免地存在一些安全隐患.关于如何解决这些隐患,为应用提供一个安全的操作平台,本文会告诉你一些最基本.最常用, ...

  9. ThoughtWorks.QRCode源码

    http://files.cnblogs.com/files/xiaoyu369/ThoughtWorks.QRCode.rar

  10. Laravel项目目录结构说明

    Laravel项目目录结构说明: |- vendor 目录包含你的 Composer 依赖模块及laravel框架. |- bootstrap 目录包含几个框架启动跟自动加载配置的文件. |- app ...