android 省市二级联动数据

时间:2017-12-03 07:27:50
【文件属性】:

文件名称:android 省市二级联动数据

文件大小:14KB

文件格式:XML

更新时间:2017-12-03 07:27:50

android spinner 省市二级联动

spProvince = (Spinner)findViewById(R.id.spAddMettingAddressProvince); spCity = (Spinner)findViewById(R.id.spAddMettingAddressCity); ArrayAdapter aAdapter = ArrayAdapter.createFromResource(this, R.array.province, android.R.layout.simple_spinner_item); aAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spProvince.setAdapter(aAdapter); spProvince.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { Spinner spinner = (Spinner)parent; String pro = (String)spinner.getItemAtPosition(position); ArrayAdapter cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.city_default, android.R.layout.simple_spinner_item); //new ArrayAdapter // (MainActivity.this,android.R.layout.simple_spinner_item, cities); //获取所在省含有哪些市(从资源数组文件中获取数据) if(pro.equals("河北省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.hebei, android.R.layout.simple_spinner_item); }else if(pro.equals("北京市")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.bj, android.R.layout.simple_spinner_item); }else if(pro.equals("山西省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.shan1xi, android.R.layout.simple_spinner_item); }else if(pro.equals("天津市")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.tianjing, android.R.layout.simple_spinner_item); }else if(pro.equals("内蒙古")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.neimeng, android.R.layout.simple_spinner_item); }else if(pro.equals("辽宁省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.liaoning, android.R.layout.simple_spinner_item); }else if(pro.equals("吉林省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.jilin, android.R.layout.simple_spinner_item); }else if(pro.equals("黑龙江省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.heilongjjiang, android.R.layout.simple_spinner_item); }else if(pro.equals("上海市")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.shanghai, android.R.layout.simple_spinner_item); }else if(pro.equals("江苏省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.jiangsu, android.R.layout.simple_spinner_item); }else if(pro.equals("浙江省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.zhejiang, android.R.layout.simple_spinner_item); }else if(pro.equals("安徽省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.anhui, android.R.layout.simple_spinner_item); }else if(pro.equals("福建省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.fujian, android.R.layout.simple_spinner_item); }else if(pro.equals("江西省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.jiangxi, android.R.layout.simple_spinner_item); }else if(pro.equals("山东省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.shandong, android.R.layout.simple_spinner_item); }else if(pro.equals("河南省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.henan, android.R.layout.simple_spinner_item); }else if(pro.equals("湖北省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.hubei, android.R.layout.simple_spinner_item); }else if(pro.equals("湖南省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.hunan, android.R.layout.simple_spinner_item); }else if(pro.equals("广东省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.guangdong, android.R.layout.simple_spinner_item); }else if(pro.equals("广西自治区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.guangxi, android.R.layout.simple_spinner_item); }else if(pro.equals("海南省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.hainan, android.R.layout.simple_spinner_item); }else if(pro.equals("重庆市")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.chongqing, android.R.layout.simple_spinner_item); }else if(pro.equals("四川省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.sichuan, android.R.layout.simple_spinner_item); }else if(pro.equals("贵州省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.guzhou, android.R.layout.simple_spinner_item); }else if(pro.equals("云南省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.yunan, android.R.layout.simple_spinner_item); }else if(pro.equals("*自治区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.xizang, android.R.layout.simple_spinner_item); }else if(pro.equals("陕西省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.shan3xi, android.R.layout.simple_spinner_item); }else if(pro.equals("甘肃省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.gansu, android.R.layout.simple_spinner_item); }else if(pro.equals("青海省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.qinghai, android.R.layout.simple_spinner_item); }else if(pro.equals("宁夏回族自治区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.ningxia, android.R.layout.simple_spinner_item); }else if(pro.equals("**自治区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.*, android.R.layout.simple_spinner_item); }else if(pro.equals("香港特别行政区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.xianggang, android.R.layout.simple_spinner_item); }else if(pro.equals("澳门特别行政区")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.aomen, android.R.layout.simple_spinner_item); }else if(pro.equals("*省")){ cityAdapter = ArrayAdapter.createFromResource (MettingAddActivity.this, R.array.*, android.R.layout.simple_spinner_item); } cityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //绑定数据到Spinner(City)上 spCity.setAdapter(cityAdapter); } @Override public void onNothingSelected(AdapterView parent) { } });


网友评论

  • 还行吧,参考了下
  • 很实用,谢谢,帮助很大.
  • 对我很有用,解决了不少问题,谢谢
  • 还可以,值得借鉴
  • 只有一个xml。。。。。。。。。。。。
  • 行,数据挺多的
  • 还行,可以借鉴
  • 可以用,就是不够动态 是用文件写死的 不方便维护
  • 例子很好,可以进行参考!
  • 不错,可以用来参考,不过许多细节还需要在考虑考虑
  • 还行吧,参考了下
  • 差评,就只有一个xml文件 不是完整的项目,没办法运行。
  • 不好,只有一个xml文件,还让我用掉1分
  • 数据很全面,主要用Java代码和资源文件实现
  • 好东西啊 有价值
  • 数据维护的挺好!感谢分享
  • 恩 挺简单的 主要用了数据 。
  • 有一定参考价值