使用:
<span style="font-family:KaiTi_GB2312;font-size:18px;"><Spinner android:id="@+id/spinner" android:layout_width="match_parent" android:layout_height="wrap_content" ></Spinner> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" /></span>
class文件MainActivity.java:
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.example.administrator.spinner1; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class MainActivity extends ActionBarActivity { private Spinner spinner; private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); spinner = (Spinner) findViewById(R.id.spinner); textView = (TextView) findViewById(R.id.textView); spinner.setPrompt("请选择三国人物:"); //下拉框开始提示 final List list = new ArrayList(); final List list1 = new ArrayList(); final List list2 = new ArrayList(); list.add("赵云"); list.add("诸葛亮"); list.add("关羽"); list.add("吕布"); list1.add("字 子龙"); list1.add("字 孔明"); list1.add("字 云长"); list1.add("字 奉先"); list2.add("武力:90 \n智力:70 \n耐力:80 "); list2.add("武力:10 \n智力:100 \n耐力:20 "); list2.add("武力:95 \n智力:60 \n耐力:80 "); list2.add("武力:100 \n智力:50 \n耐力:70 "); ArrayAdapter adpter = new ArrayAdapter(this, android.R.layout.simple_spinner_item,list); spinner.setAdapter(adpter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id ){ textView.setText("已选择:"+list.get(position)+":\t"+list1.get(position)); textView.append("\n个人信息:\n"+list2.get(position)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } }</span>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/j_a_v_a_guan/article/details/48152075