线上服务咨询
Spinner实现了城市连接选择
发表时间:2019-07-30 16:31:13
文章来源:沈阳软件开发
标签:网站建设 小程序开发 小程序制作 微信小程序开发 公众号开发 微信公众号开发 网页设计 网站优化 网站排名 网站设计 微信小程序设计 小程序定制 微信小程序定制
浏览次数:0
在上一篇文章中,我了解了Spinner的简单用法。我知道Spinner的数据源通常有两种形式。
XML文件和数组的方式。这次,主要内容是实现Spinner上省与城市的三级联动,所以我没有太多话要说
直接在效果图上!
城市信息我把他放在strings.xml文件中,具体没有给出,信息太大
主要的xml文件如下:
[java]查看plaincopyprint?
Arg0,查看arg1,
Int arg2,long arg3){
provinceId=province_spinner.getSelectedItemPosition();
strProvince=province_spinner.getSelectedItem()
.toString(); //获取所选内容,这是省的名称
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('请选择城市'); //设置标题
选择(city_spinner,city_adapter,city [provinceId]); //城市级数据绑定
/*表示该市的省和市的城市收集[provinceId]
* R. Array.beijing */
City_spinner
.setOnItemSelectedListener(new OnItemSelectedListener(){
@override
公共无效onItemSelected(
AdapterViewarg0,查看arg1,
Int arg2,long arg3){
cityId=city_spinner
.getSelectedItemPosition(); //获取城市的id
strCity=city_spinner
.getSelectedItem()
.toString(); //获取城市的内容
Log.v('test','city:'
+ city_spinner
.getSelectedItem()
.toString()//输出测试
+ cityId.toString());
如果(真){
//开始在这里设置县级内容
County_spinner=(Spinner)findViewById(R.id.county_spinner);
County_spinner
.setPrompt('请选择县]);
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]);
打破;
默认值:
打破;
}
County_spinner
.setOnItemSelectedListener(new OnItemSelectedListener(){
@override
公共无效onItemSelected(
AdapterViewarg0,
查看arg1,
Int arg2,
长arg3){
strCounty=county_spinner
.getSelectedItem()
的ToString();
display.setText(strProvince
+' - '
+ strCity
+' - '
+ strCounty);
}
@override
公共无效onNothingSelected(
AdapterViewarg0){
}
});
}
}
@override公共无效onNothingSelected(
AdapterViewarg0){
//TODO自动生成的方法存根
}
});
}
}
@override
Public void onNothingSelected(AdapterViewarg0){
}
});
}
/*通过方法*/
动态添加适配器Private void select(Spinner spin,ArrayAdapter adapter,
Int arry){
//注意这里的arry不仅仅是一个整数,他代表一个数组!
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);
标签:& nbsp& nbsp沈阳app开发&用于城市链接选择的营销类型网站建设& nbsp沈阳App Design& nbspSpinner网站建设,小程序开发,小程序制作,微信小程序开发,公众号开发,微信公众号开发,网页设计,网站优化,网站排名,网站设计,微信小程序设计,小程序定制,微信小程序定制