android 之Spinner下拉菜單實(shí)現(xiàn)級(jí)聯(lián)
效果圖如下:
默認(rèn)第一次加載

選擇原始隊(duì)列:

級(jí)聯(lián)效果圖:

關(guān)鍵代碼給下拉列表選中事件監(jiān)聽綁定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="執(zhí)行調(diào)度"
android:textSize="18sp" >
</Button>
</LinearLayout>
JAVA 程序代碼:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
public class ManageInfo_Activity extends Activity implements OnClickListener {
private Context context;
private static final String[] queuilist = { "A999", "B888" };
private static final String[] default_linfo = { "A01", "A02", "A03", "A04",
"A05", "A06", "A07", "A08", "A09", "A10", "A11" };
private static final String[][] queu_info = new String[][] {
{ "A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08", "A09",
"A10", "A11" },
{ "B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B09",
"B10", "B11" } };
private TextView firsthand_dlbh_view;
private Spinner firsthand_dlbh_pinner;
private ArrayAdapter<String> firsthand_dlbh_adapter;
private TextView firsthand_pdbh_view;
private Spinner firsthand_pdbh_spinner;
private ArrayAdapter<String> firsthand_pdbh_adapter;
private TextView target_dlbh_view;
private Spinner target_dlbh_spinner;
private ArrayAdapter<String> target_dlbh_adapter;
private String firsthand_dlbh = "";
private String firsthand_pdbh = "";
private String target_dlbh = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manageinfo);
context = this;
// 定義原始隊(duì)列編號(hào)下拉菜單
firsthand_dlbh_view = (TextView) findViewById(R.id.firsthand_dlbh);
firsthand_dlbh_pinner = (Spinner) findViewById(R.id.firsthand_dlbh_pinner);
// 將可選內(nèi)容與ArrayAdapter連接起來(lái)
firsthand_dlbh_adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, queuilist);
// 設(shè)置下拉列表的風(fēng)格
firsthand_dlbh_adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 將adapter 添加到spinner中
firsthand_dlbh_pinner.setAdapter(firsthand_dlbh_adapter);
// 添加事件Spinner事件監(jiān)聽
firsthand_dlbh_pinner
.setOnItemSelectedListener(new FirsthanddlbhSpinnerSelectedListener());
// 設(shè)置默認(rèn)值
firsthand_dlbh_pinner.setVisibility(View.VISIBLE);
// 定義原始排隊(duì)編號(hào)下拉菜單
firsthand_pdbh_view = (TextView) findViewById(R.id.firsthand_pdbh);
firsthand_pdbh_spinner = (Spinner) findViewById(R.id.firsthand_pdbh_pinner);
// 將可選內(nèi)容與ArrayAdapter連接起來(lái)
firsthand_pdbh_adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, default_linfo);
// 設(shè)置下拉列表的風(fēng)格
firsthand_pdbh_adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 將adapter 添加到spinner中
firsthand_pdbh_spinner.setAdapter(firsthand_pdbh_adapter);
// 添加事件Spinner事件監(jiān)聽
firsthand_pdbh_spinner
.setOnItemSelectedListener(new FirsthandpdbhSpinnerSelectedListener());
// 設(shè)置默認(rèn)值
firsthand_pdbh_spinner.setVisibility(View.VISIBLE);
// 定義目標(biāo)隊(duì)列下拉菜單
target_dlbh_view = (TextView) findViewById(R.id.target_dlbh);
target_dlbh_spinner = (Spinner) findViewById(R.id.target_dlbh_spinner);
// 將可選內(nèi)容與ArrayAdapter連接起來(lái)
target_dlbh_adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, queuilist);
// 設(shè)置下拉列表的風(fēng)格
target_dlbh_adapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 將adapter 添加到spinner中
target_dlbh_spinner.setAdapter(target_dlbh_adapter);
// 添加事件Spinner事件監(jiān)聽
target_dlbh_spinner
.setOnItemSelectedListener(new TargetdlbhpinnerSelectedListener());
// 設(shè)置默認(rèn)值
target_dlbh_spinner.setVisibility(View.VISIBLE);
Button diff_manage_operation = (Button) findViewById(R.id.diff_manage_operation);
diff_manage_operation.setOnClickListener(this);
}
// 選擇 目標(biāo)排隊(duì)編號(hào) 事件 監(jiān)聽器
class FirsthanddlbhSpinnerSelectedListener implements
OnItemSelectedListener {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
firsthand_dlbh = queuilist[arg2];
firsthand_dlbh_view.setText("選擇原始隊(duì)列是:" + queuilist[arg2]);
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);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}
// 選擇 目標(biāo)排隊(duì)編號(hào) 事件 監(jiān)聽器
class FirsthandpdbhSpinnerSelectedListener implements
OnItemSelectedListener {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
firsthand_pdbh = (String) firsthand_pdbh_spinner
.getItemAtPosition(arg2);
firsthand_pdbh_view.setText("要移動(dòng)的排隊(duì)編號(hào)是:"
+ (String) firsthand_pdbh_spinner.getItemAtPosition(arg2));
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}
// //選擇 參照排隊(duì)編號(hào) 事件 監(jiān)聽器
class TargetdlbhpinnerSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
target_dlbh = queuilist[arg2];
target_dlbh_view.setText("移動(dòng)到 " + queuilist[arg2] + " 隊(duì)列中 ");
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}
@Override
public void onClick(View v) {
System.out.println(" 進(jìn)入同一隊(duì)列調(diào)度環(huán)節(jié)");
System.out.println("執(zhí)行把排隊(duì)編號(hào) " + firsthand_pdbh + " 從 " + firsthand_dlbh
+ " 隊(duì)列中移動(dòng)到 " + target_dlbh + " 隊(duì)列的末尾操作 ");
// DiffMangerQuening( user_name, estination_code, firsthand_dlbh, firsthand_dlbh,target_dlbh); // switch(v.getId()){//根據(jù)點(diǎn)擊不同的按鈕,彈出相應(yīng)的提示
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
相關(guān)文章
為Android應(yīng)用增加渠道信息 自動(dòng)化不同渠道的打包過(guò)程的使用詳解
為了統(tǒng)計(jì)渠道信息,就不得不在程序的某個(gè)地方加入渠道的信息,然后針對(duì)不同的渠道打不同的包。一般可以在Manifest文件中加入渠道編號(hào),而不直接寫在代碼中。這樣做的好處是,可以針對(duì)不同渠道,自動(dòng)化去修改Manifest文件中的渠道編號(hào),然后自動(dòng)為該渠道打包2013-05-05
Android字符串和十六進(jìn)制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問(wèn)題
這篇文章主要介紹了Android字符串和十六進(jìn)制相互轉(zhuǎn)化出現(xiàn)的中文亂碼問(wèn)題的相關(guān)資料,需要的朋友可以參考下2016-02-02
Android實(shí)現(xiàn)彈出輸入法時(shí)頂部固定中間部分上移的效果
本文主要介紹了Android實(shí)現(xiàn)彈出輸入法時(shí)頂部固定中間部分上移的效果的方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-03-03
android自定義環(huán)形統(tǒng)計(jì)圖動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了android自定義環(huán)形統(tǒng)計(jì)圖動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07
Android網(wǎng)絡(luò)開發(fā)中GET與POST請(qǐng)求詳解
這篇文章主要介紹了android實(shí)現(xiàn)網(wǎng)絡(luò)請(qǐng)求的get和post請(qǐng)求的簡(jiǎn)單封裝與使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧<BR>2022-12-12
Android實(shí)現(xiàn)向Launcher添加快捷方式的方法
這篇文章主要介紹了Android實(shí)現(xiàn)向Launcher添加快捷方式的方法,涉及Android添加快捷方式的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
Android跨進(jìn)程傳遞大數(shù)據(jù)的方法實(shí)現(xiàn)
這篇文章主要介紹了Android跨進(jìn)程傳遞大數(shù)據(jù)的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03

