// 适配器
private ArrayAdapter<String> yearAdapter;
private TextView user;
private Button btn;
Calendar cal = Calendar.getInstance();
String year = String.valueOf(cal.get(Calendar.YEAR));
yearLists = new ArrayList<String>();
yearLists.add(year);
yearAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, yearLists);
yearAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(yearAdapter);
spinner1.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
/* 将所选mySpinner 的值带入myTextView 中 */
/* user.setText("您选择的是:"+ adapter.getItem(arg2)); */
/* 将mySpinner 显示 */
// arg0.setVisibility(View.VISIBLE);
yearIndex = arg2;
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
/* user.setText("NONE"); */
arg0.setVisibility(View.VISIBLE);
}
});
activity_second.xml
<?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:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:background="@drawable/info_bg" >
<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:textSize="50dp"
android:textColor="#000000"
android:text="aaa"
/>
<!-- 学年 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textColor="#000000"
android:text="学年" />
<Spinner
android:id="@+id/sp01"
android:layout_width="250dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<!-- 考点 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textColor="#000000"
android:text="考点" />
<Spinner
android:id="@+id/sp02"
android:layout_width="250dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<!-- 专业 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textColor="#000000"
android:text="专业" />
<Spinner
android:id="@+id/sp03"
android:layout_width="250dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp" />
</LinearLayout>
<!-- 确定按钮,跳转到学生信息列表 -->
<Button
android:id="@+id/Button01"
android:layout_width="300dp"
android:layout_height="80dp"
android:layout_marginTop="200dp"
android:background="@drawable/shape"
android:text="确定"
android:textColor="#FFFFFF"
android:textSize="40dp" />
</LinearLayout>