先是在 layout 里面 建议个 Spinner 控件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >        <Spinner         android:id="@+id/spnner"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        />    </LinearLayout>

然后在 主activity 里

package so.com;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.Spinner;import android.widget.TextView;import android.widget.Toast;public class SoActivity extends Activity {    /** Called when the activity is first created. */private List<String> list = new ArrayList<String>();private Spinner spinner;private ArrayAdapter<String> adapter;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                spinner = (Spinner)findViewById(R.id.spnner);                        list.add("北京");        list.add("上海");        list.add("天津");        list.add("南京");                      adapter = new ArrayAdapter<String>(SoActivity.this, android.R.layout.simple_spinner_item, list);           adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);         spinner.setAdapter(adapter);                ///增加监听事件,其实在程序启动时就调用了该监听        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {        public void onItemSelected(AdapterView<?> arg0, View arg1,        int arg2, long arg3) {        // TODO Auto-generated method stub                Toast.makeText(SoActivity.this, adapter.getItem(arg2), Toast.LENGTH_LONG).show();                }public void onNothingSelected(AdapterView<?> arg0) {// TODO Auto-generated method stubToast.makeText(SoActivity.this, "Selected None", Toast.LENGTH_LONG).show();}});                                  }}

更多相关文章

  1. Android增加监听的三种实现方式
  2. Android中短信的收发机制 发送短信 接收短信 拦截短信 监听短信
  3. android 输入框自动匹配-AutoCompleteTextView
  4. android View 绘制完成监听
  5. android 呼入电话的监听(来电监听)
  6. Android导航滑动文字渐变+底部指示条
  7. android之知识点小结二
  8. Android监听返回键
  9. Android实现多层级Spinner列表选项实时更新树形层级

随机推荐

  1. 浅析:Android WebView 常见的九个问题
  2. Android中开源库EventBus使用详解
  3. Android(安卓)消息队列模型详解及实例
  4. 我的android 第二天 - 短信发送器
  5. Android中onInterceptTouchEvent与onTouc
  6. Android studio之build配置
  7. Android学习-五布局之相对布局
  8. android linker 浅析
  9. 手机操作系统开源软件
  10. android发送与接收超长短信