Android 之 Spinner 下拉菜單實現級聯效果圖如下:
默認第一次加載
選擇原始隊列:
級聯效果圖:
關鍵代碼給下拉列表選中事件監聽綁定Id :
int pos = firsthand_dlbh_pinner.getSelectedItemPosition();
firsthand_pdbh_adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_spinner_item, queu_info[pos]);
firsthand_pdbh_spinner.setAdapter(firsthand_pdbh_adapter);
完整代碼:
布局文件代碼:
<?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" >
<TextView
android:id="@+id/firsthand_dlbh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</TextView>
<Spinner
android:id="@+id/firsthand_dlbh_pinner"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</Spinner>
<TextView
android:id="@+id/firsthand_pdbh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</TextView>
<Spinner
android:id="@+id/firsthand_pdbh_pinner"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</Spinner>
<TextView
android:id="@+id/target_dlbh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</TextView>
<Spinner
android:id="@+id/target_dlbh_spinner"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_marginLeft="60sp"
android:layout_marginTop="20sp" >
</Spinner>
<Button
android:id="@+id/diff_manage_operation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100sp"
android:layout_marginTop="20sp"
android:text="執行調度"
android:textSize="18sp" >
</Button>
</LinearLayout>