線上服務(wù)咨詢(xún)
Article/文章
記錄成長(zhǎng)點(diǎn)滴 分享您我感悟
您當(dāng)前位置>首頁(yè) > 知識(shí) > 網(wǎng)站建設(shè)
Spinner實(shí)現(xiàn)了城市連接選擇
發(fā)表時(shí)間:2019-07-30 16:31:13
文章來(lái)源:沈陽(yáng)軟件開(kāi)發(fā)
標(biāo)簽:網(wǎng)站建設(shè) 小程序開(kāi)發(fā) 小程序制作 微信小程序開(kāi)發(fā) 公眾號(hào)開(kāi)發(fā) 微信公眾號(hào)開(kāi)發(fā) 網(wǎng)頁(yè)設(shè)計(jì) 網(wǎng)站優(yōu)化 網(wǎng)站排名 網(wǎng)站設(shè)計(jì) 微信小程序設(shè)計(jì) 小程序定制 微信小程序定制
瀏覽次數(shù):0
在上一篇文章中,我了解了Spinner的簡(jiǎn)單用法。我知道Spinner的數(shù)據(jù)源通常有兩種形式。
XML文件和數(shù)組的方式。這次,主要內(nèi)容是實(shí)現(xiàn)Spinner上省與城市的三級(jí)聯(lián)動(dòng),所以我沒(méi)有太多話要說(shuō)
直接在效果圖上!
城市信息我把他放在strings.xml文件中,具體沒(méi)有給出,信息太大
主要的xml文件如下:
[java]查看plaincopyprint?
Arg0,查看arg1,
Int arg2,long arg3){
provinceId=province_spinner.getSelectedItemPosition();
strProvince=province_spinner.getSelectedItem()
.toString(); //獲取所選內(nèi)容,這是省的名稱(chēng)
City_spinner=(Spinner)findViewById(R.id.city_spinner);
如果(真){
System.out.println('省:'
+ province_spinner.getSelectedItem()
.toString()+ provinceId.toString());
County_spinner=(Spinner)findViewById(R.id.county_spinner);
City_spinner=(Spinner)findViewById(R.id.city_spinner);
city_spinner.setPrompt('請(qǐng)選擇城市'); //設(shè)置標(biāo)題
選擇(city_spinner,city_adapter,city [provinceId]); //城市級(jí)數(shù)據(jù)綁定
/*表示該市的省和市的城市收集[provinceId]
* R. Array.beijing */
City_spinner
.setOnItemSelectedListener(new OnItemSelectedListener(){
@override
公共無(wú)效onItemSelected(
AdapterViewarg0,查看arg1,
Int arg2,long arg3){
cityId=city_spinner
.getSelectedItemPosition(); //獲取城市的id
strCity=city_spinner
.getSelectedItem()
.toString(); //獲取城市的內(nèi)容
Log.v('test','city:'
+ city_spinner
.getSelectedItem()
.toString()//輸出測(cè)試
+ cityId.toString());
如果(真){
//開(kāi)始在這里設(shè)置縣級(jí)內(nèi)容
County_spinner=(Spinner)findViewById(R.id.county_spinner);
County_spinner
.setPrompt('請(qǐng)選擇縣]);
Switch(provinceId){
案例0:
選擇(county_spinner,
County_adapter,
countyOfBeiJing [cityId]);
打破;
案例1:
選擇(county_spinner,
County_adapter,
countyOfTianJing [cityId]);
打破;
案例2:
選擇(county_spinner,
County_adapter,
countyOfHeBei [cityId]);
打破;
案例3:
選擇(county_spinner,
County_adapter,
countyOfShanXi1 [cityId]);
打破;
案例4:
選擇(county_spinner,
County_adapter,
countyOfNeiMengGu [cityId]);
打破;
案例5:
選擇(county_spinner,
County_adapter,
countyOfLiaoNing [cityId]);
打破;
案例6:
選擇(county_spinner,
County_adapter,
countyOfJiLin [cityId]);
打破;
案例7:
選擇(county_spinner,County_adapter,
countyOfHeiLongJiang [cityId]);
打破;
案例8:
選擇(county_spinner,
County_adapter,
countyOfShangHai [cityId]);
打破;
案例9:
選擇(county_spinner,
County_adapter,
countyOfJiangSu [cityId]);
打破;
案例10:
選擇(county_spinner,
County_adapter,
countyOfZheJiang [cityId]);
打破;
案例11:
選擇(county_spinner,
County_adapter,
countyOfAnHui [cityId]);
打破;
案例12:
選擇(county_spinner,
County_adapter,countyOfFuJian [cityId]);
打破;
案例13:
選擇(county_spinner,
County_adapter,
countyOfJiangXi [cityId]);
打破;
案例14:
選擇(county_spinner,
County_adapter,
countyOfShanDong [cityId]);
打破;
案例15:
選擇(county_spinner,
County_adapter,
countyOfHeNan [cityId]);
打破;
案例16:
選擇(county_spinner,
County_adapter,
countyOfHuBei [cityId]);
打破;
案例17:
選擇(county_spinner,
County_adapter,
countyOfHuNan [cityId]);打破;
案例18:
選擇(county_spinner,
County_adapter,
countyOfGuangDong [cityId]);
打破;
案例19:
選擇(county_spinner,
County_adapter,
countyOfGuangXi [cityId]);
打破;
案例20:
選擇(county_spinner,
County_adapter,
countyOfHaiNan [cityId]);
打破;
案例21:
選擇(county_spinner,
County_adapter,
countyOfChongQing [cityId]);
打破;
案例22:
選擇(county_spinner,
County_adapter,
countyOfSiChuan [cityId]);
打破;案例23:
選擇(county_spinner,
County_adapter,
countyOfGuiZhou [cityId]);
打破;
案例24:
選擇(county_spinner,
County_adapter,
countyOfYunNan [cityId]);
打破;
案例25:
選擇(county_spinner,
County_adapter,
countyOfXiZang [cityId]);
打破;
案例26:
選擇(county_spinner,
County_adapter,
countyOfShanXi2 [cityId]);
打破;
案例27:
選擇(county_spinner,
County_adapter,
countyOfGanSu [cityId]);
打破;
選擇(county_spinner,
County_adapter,
countyOfQingHai [cityId]);
打破;
案例29:
選擇(county_spinner,
County_adapter,
countyOfNingXia [cityId]);
打破;
案例30:
選擇(county_spinner,
County_adapter,
countyOfXinJiang [cityId]);
打破;
案例31:
選擇(county_spinner,
County_adapter,
countyOfHongKong [cityId]);
打破;
案例32:
選擇(county_spinner,
County_adapter,
countyOfAoMen [cityId]);
打破;
案例33:
選擇(county_spinner,
County_adapter,countyOfTaiWan [cityId]);
打破;
默認(rèn)值:
打破;
}
County_spinner
.setOnItemSelectedListener(new OnItemSelectedListener(){
@override
公共無(wú)效onItemSelected(
AdapterViewarg0,
查看arg1,
Int arg2,
長(zhǎng)arg3){
strCounty=county_spinner
.getSelectedItem()
的ToString();
display.setText(strProvince
+' - '
+ strCity
+' - '
+ strCounty);
}
@override
公共無(wú)效onNothingSelected(
AdapterViewarg0){
}
});
}
}
@override公共無(wú)效onNothingSelected(
AdapterViewarg0){
//TODO自動(dòng)生成的方法存根
}
});
}
}
@override
Public void onNothingSelected(AdapterViewarg0){
}
});
}
/*通過(guò)方法*/
動(dòng)態(tài)添加適配器Private void select(Spinner spin,ArrayAdapter adapter,
Int arry){
//注意這里的arry不僅僅是一個(gè)整數(shù),他代表一個(gè)數(shù)組!
Adapter=ArrayAdapter.createFromResource(this,arry,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(適配器);
//spin.setSelection(0,true);
標(biāo)簽:& nbsp& nbsp沈陽(yáng)app開(kāi)發(fā)&用于城市鏈接選擇的營(yíng)銷(xiāo)類(lèi)型網(wǎng)站建設(shè)& nbsp沈陽(yáng)App Design& nbspSpinner網(wǎng)站建設(shè),小程序開(kāi)發(fā),小程序制作,微信小程序開(kāi)發(fā),公眾號(hào)開(kāi)發(fā),微信公眾號(hào)開(kāi)發(fā),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站優(yōu)化,網(wǎng)站排名,網(wǎng)站設(shè)計(jì),微信小程序設(shè)計(jì),小程序定制,微信小程序定制