标签:bss tpc cnp mdi contex avg iba css epc
1.布局文件定义一个是spinner
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="5dp" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="选择您的排位分段" android:textColor="#44BDED" android:textSize="18sp" /> <Spinner android:id="@+id/spin_one" android:layout_width="fill_parent" android:layout_height="wrap_content" android:entries="@array/data" android:spinnerMode="dialog" /> </LinearLayout>
2.Activity初始化Spinner
package com.example.spinnerdemo; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.Spinner; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Spinner spinner=(Spinner) findViewById(R.id.spin_one); List<String> list = new ArrayList<String>(); list.add("选项1"); list.add("选项3"); list.add("选项2"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list); spinner.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
3.效果:
如果页面中不初始化list。
定义一个数组文件:
myarrays.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="data"> <item>英勇青铜</item> <item>不屈白银</item> <item>荣耀黄金</item> <item>华贵铂金</item> <item>璀璨钻石</item> <item>超凡大师</item> <item>最强王者</item> </string-array> </resources>
页面效果:
标签:bss tpc cnp mdi contex avg iba css epc
原文地址:http://www.cnblogs.com/qlqwjy/p/7519972.html