private TextView tv1; private Spinner sp1; private ArrayAdapter
adapter; //1.创建数据源 private String[] ss = {"江岸区","江汉区","硚口区","武昌区","青山区","汉阳区","经开区"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1 = (TextView) findViewById(R.id.textView1); sp1 = (Spinner) findViewById(R.id.spinner1); //2.初始化一个Adapter,并在其中绑定数据源 adapter = new ArrayAdapter
(this, android.R.layout.simple_spinner_item, ss); //3.设置下拉列表风格 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //4.将Adapter绑定到Spinner上 //5.添加Spinner点选事件的监听 sp1.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView
parent, View view, int position, long id) { // TODO Auto-generated method stub tv1.setText("你的出生地区是:"+ss[position]); } @Override public void onNothingSelected(AdapterView
parent) { // TODO Auto-generated method stub } }); }