全国省市xml文件下载
xml布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="省:"
android:textSize="20dp" />
<Spinner
android:id="@+id/sp_province"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:entries="@array/languages" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="| 市:"
android:textSize="20dp" />
<Spinner
android:id="@+id/sp_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#FFFFFF" />
LinearLayout>
LinearLayout>
Activity代码:
package com.wh;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
Spinner city;
Spinner province;
String tProvince;
String tCity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
province = (Spinner) findViewById(R.id.sp_province);
city = (Spinner) findViewById(R.id.sp_city);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.province,
R.layout.spinner_checked_text);
province.setAdapter(adapter);
province.setOnItemSelectedListener(new spinnerItemSelected());
city.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
tCity = city.getSelectedItem().toString();
}
@Override
public void onNothingSelected(AdapterView> parent) {
}
});
}
// 二级联动adapter
class spinnerItemSelected implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
Spinner spinner = (Spinner) parent;
String pro = (String) spinner.getItemAtPosition(position);
tProvince = province.getSelectedItem().toString();
// 处理省的市的显示
ArrayAdapter cityadapter = ArrayAdapter.createFromResource(getApplicationContext(),
R.array.def, R.layout.spinner_checked_text);
if (pro.equals("北京")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.北京,
R.layout.spinner_checked_text);
} else if (pro.equals("天津")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.天津,
R.layout.spinner_checked_text);
} else if (pro.equals("河北")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.河北,
R.layout.spinner_checked_text);
} else if (pro.equals("山西")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.山西,
R.layout.spinner_checked_text);
} else if (pro.equals("内蒙古")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.内蒙古,
R.layout.spinner_checked_text);
} else if (pro.equals("辽宁")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.辽宁,
R.layout.spinner_checked_text);
} else if (pro.equals("吉林")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.吉林,
R.layout.spinner_checked_text);
} else if (pro.equals("黑龙江")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.黑龙江,
R.layout.spinner_checked_text);
} else if (pro.equals("上海")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.上海,
R.layout.spinner_checked_text);
} else if (pro.equals("江苏")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.江苏,
R.layout.spinner_checked_text);
} else if (pro.equals("浙江")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.浙江,
R.layout.spinner_checked_text);
} else if (pro.equals("安徽")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.安徽,
R.layout.spinner_checked_text);
} else if (pro.equals("福建")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.福建,
R.layout.spinner_checked_text);
} else if (pro.equals("江西")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.江西,
R.layout.spinner_checked_text);
} else if (pro.equals("山东")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.山东,
R.layout.spinner_checked_text);
} else if (pro.equals("河南")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.河南,
R.layout.spinner_checked_text);
} else if (pro.equals("湖北")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.湖北,
R.layout.spinner_checked_text);
} else if (pro.equals("湖南")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.湖南,
R.layout.spinner_checked_text);
} else if (pro.equals("广东")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.广东,
R.layout.spinner_checked_text);
} else if (pro.equals("广西")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.广西,
R.layout.spinner_checked_text);
} else if (pro.equals("海南")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.海南,
R.layout.spinner_checked_text);
} else if (pro.equals("重庆")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.重庆,
R.layout.spinner_checked_text);
} else if (pro.equals("四川")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.四川,
R.layout.spinner_checked_text);
} else if (pro.equals("贵州")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.贵州,
R.layout.spinner_checked_text);
} else if (pro.equals("云南")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.云南,
R.layout.spinner_checked_text);
} else if (pro.equals("西藏")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.西藏,
R.layout.spinner_checked_text);
} else if (pro.equals("陕西")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.陕西,
R.layout.spinner_checked_text);
} else if (pro.equals("甘肃")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.甘肃,
R.layout.spinner_checked_text);
} else if (pro.equals("青海")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.青海,
R.layout.spinner_checked_text);
} else if (pro.equals("宁夏")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.宁夏,
R.layout.spinner_checked_text);
} else if (pro.equals("新疆")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.新疆,
R.layout.spinner_checked_text);
} else if (pro.equals("台湾")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.台湾,
R.layout.spinner_checked_text);
} else if (pro.equals("香港")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.香港,
R.layout.spinner_checked_text);
} else if (pro.equals("澳门")) {
cityadapter = ArrayAdapter.createFromResource(getApplicationContext(), R.array.澳门,
R.layout.spinner_checked_text);
}
city.setAdapter(cityadapter);
}
@Override
public void onNothingSelected(AdapterView> parent) {
}
}
}
全国省市XML文件:
arrays.xml:
version="1.0" encoding="utf-8"?>
<string-array name="province">
<item>-省份-item>
<item>北京item>
<item>天津item>
<item>河北item>
<item>山西item>
<item>内蒙古item>
<item>辽宁item>
<item>吉林item>
<item>黑龙江item>
<item>上海item>
<item>江苏item>
<item>浙江item>
<item>安徽item>
<item>福建item>
<item>江西item>
<item>山东item>
<item>河南item>
<item>湖北item>
<item>湖南item>
<item>广东item>
<item>广西item>
<item>海南item>
<item>重庆item>
<item>四川item>
<item>贵州item>
<item>云南item>
<item>西藏item>
<item>陕西item>
<item>甘肃item>
<item>青海item>
<item>宁夏item>
<item>新疆item>
<item>台湾item>
<item>香港item>
<item>澳门item>
string-array>
<string-array name="def">
<item>-城市-item>
string-array>
<string-array name="北京">
<item>-城市-item>
<item>东城item>
<item>西城item>
<item>朝阳item>
<item>丰台item>
<item>石景山item>
<item>海淀item>
<item>门头沟item>
<item>房山item>
<item>通州item>
<item>顺义item>
<item>昌平item>
<item>大兴item>
<item>平谷item>
<item>怀柔item>
<item>密云item>
<item>延庆item>
string-array>
<string-array name="天津">
<item>-城市-item>
<item>和平item>
<item>河东item>
<item>河西item>
<item>南开item>
<item>河北item>
<item>红桥item>
<item>滨海新区item>
<item>东丽item>
<item>西青item>
<item>津南item>
<item>北辰item>
<item>宁河item>
<item>武清item>
<item>静海item>
<item>宝坻item>
<item>蓟县item>
string-array>
<string-array name="河北">
<item>-城市-item>
<item>石家庄item>
<item>唐山item>
<item>秦皇岛item>
<item>邯郸item>
<item>邢台item>
<item>保定item>
<item>张家口item>
<item>承德item>
<item>沧州item>
<item>廊坊item>
<item>衡水item>
string-array>
<string-array name="山西">
<item>-城市-item>
<item>太原item>
<item>大同item>
<item>阳泉item>
<item>长治item>
<item>晋城item>
<item>朔州item>
<item>晋中item>
<item>运城item>
<item>忻州item>
<item>临汾item>
<item>吕梁item>
string-array>
<string-array name="内蒙古">
<item>-城市-item>
<item>呼和浩特item>
<item>包头item>
<item>乌海item>
<item>赤峰item>
<item>通辽item>
<item>鄂尔多斯item>
<item>呼伦贝尔item>
<item>巴彦淖尔item>
<item>乌兰察布item>
<item>兴安item>
<item>锡林郭勒item>
<item>阿拉善item>
string-array>
<string-array name="辽宁">
<item>-城市-item>
<item>沈阳item>
<item>大连item>
<item>鞍山item>
<item>抚顺item>
<item>本溪item>
<item>丹东item>
<item>锦州item>
<item>营口item>
<item>阜新item>
<item>辽阳item>
<item>盘锦item>
<item>铁岭item>
<item>朝阳item>
<item>葫芦岛item>
string-array>
<string-array name="吉林">
<item>-城市-item>
<item>长春item>
<item>吉林item>
<item>四平item>
<item>辽源item>
<item>通化item>
<item>白山item>
<item>松原item>
<item>白城item>
<item>延边item>
string-array>
<string-array name="黑龙江">
<item>-城市-item>
<item>哈尔滨item>
<item>齐齐哈尔item>
<item>鸡西item>
<item>鹤岗item>
<item>双鸭山item>
<item>大庆item>
<item>伊春item>
<item>佳木斯item>
<item>七台河item>
<item>牡丹江item>
<item>黑河item>
<item>绥化item>
<item>大兴安岭item>
string-array>
<string-array name="上海">
<item>-城市-item>
<item>黄浦item>
<item>卢湾item>
<item>徐汇item>
<item>长宁item>
<item>静安item>
<item>普陀item>
<item>闸北item>
<item>虹口item>
<item>杨浦item>
<item>闵行item>
<item>宝山item>
<item>嘉定item>
<item>浦东新区item>
<item>金山item>
<item>松江item>
<item>奉贤item>
<item>青浦item>
<item>崇明item>
string-array>
<string-array name="江苏">
<item>-城市-item>
<item>南京item>
<item>无锡item>
<item>徐州item>
<item>常州item>
<item>苏州item>
<item>南通item>
<item>连云港item>
<item>淮安item>
<item>盐城item>
<item>扬州item>
<item>镇江item>
<item>泰州item>
<item>宿迁item>
string-array>
<string-array name="浙江">
<item>-城市-item>
<item>杭州item>
<item>宁波item>
<item>温州item>
<item>嘉兴item>
<item>湖州item>
<item>绍兴item>
<item>金华item>
<item>衢州item>
<item>舟山item>
<item>台州item>
<item>丽水item>
string-array>
<string-array name="安徽">
<item>-城市-item>
<item>合肥item>
<item>芜湖item>
<item>蚌埠item>
<item>淮南item>
<item>马鞍山item>
<item>淮北item>
<item>铜陵item>
<item>安庆item>
<item>黄山item>
<item>滁州item>
<item>阜阳item>
<item>宿州item>
<item>六安item>
<item>亳州item>
<item>池州item>
<item>宣城item>
string-array>
<string-array name="福建">
<item>-城市-item>
<item>福州item>
<item>厦门item>
<item>莆田item>
<item>三明item>
<item>泉州item>
<item>漳州item>
<item>南平item>
<item>龙岩item>
<item>宁德item>
string-array>
<string-array name="江西">
<item>-城市-item>
<item>南昌item>
<item>景德镇item>
<item>萍乡item>
<item>九江item>
<item>新余item>
<item>鹰潭item>
<item>赣州item>
<item>吉安item>
<item>宜春item>
<item>抚州item>
<item>上饶item>
string-array>
<string-array name="山东">
<item>-城市-item>
<item>济南item>
<item>青岛item>
<item>淄博item>
<item>枣庄item>
<item>东营item>
<item>烟台item>
<item>潍坊item>
<item>济宁item>
<item>泰安item>
<item>威海item>
<item>日照item>
<item>莱芜item>
<item>临沂item>
<item>德州item>
<item>聊城item>
<item>滨州item>
<item>菏泽item>
string-array>
<string-array name="河南">
<item>-城市-item>
<item>郑州item>
<item>开封item>
<item>洛阳item>
<item>平顶山item>
<item>安阳item>
<item>鹤壁item>
<item>新乡item>
<item>焦作item>
<item>濮阳item>
<item>许昌item>
<item>漯河item>
<item>三门峡item>
<item>南阳item>
<item>商丘item>
<item>信阳item>
<item>周口item>
<item>驻马店item>
<item>济源item>
string-array>
<string-array name="湖北">
<item>-城市-item>
<item>武汉item>
<item>黄石item>
<item>十堰item>
<item>宜昌item>
<item>襄阳item>
<item>鄂州item>
<item>荆门item>
<item>孝感item>
<item>荆州item>
<item>黄冈item>
<item>咸宁item>
<item>随州item>
<item>恩施item>
<item>仙桃item>
<item>潜江item>
<item>天门item>
<item>神农架item>
string-array>
<string-array name="湖南">
<item>-城市-item>
<item>长沙item>
<item>株洲item>
<item>湘潭item>
<item>衡阳item>
<item>邵阳item>
<item>岳阳item>
<item>常德item>
<item>张家界item>
<item>益阳item>
<item>郴州item>
<item>永州item>
<item>怀化item>
<item>娄底item>
<item>湘西item>
string-array>
<string-array name="广东">
<item>-城市-item>
<item>广州item>
<item>韶关item>
<item>深圳item>
<item>珠海item>
<item>汕头item>
<item>佛山item>
<item>江门item>
<item>湛江item>
<item>茂名item>
<item>肇庆item>
<item>惠州item>
<item>梅州item>
<item>汕尾item>
<item>河源item>
<item>阳江item>
<item>清远item>
<item>东莞item>
<item>中山item>
<item>潮州item>
<item>揭阳item>
<item>云浮item>
string-array>
<string-array name="广西">
<item>-城市-item>
<item>南宁item>
<item>柳州item>
<item>桂林item>
<item>梧州item>
<item>北海item>
<item>防城港item>
<item>钦州item>
<item>贵港item>
<item>玉林item>
<item>百色item>
<item>贺州item>
<item>河池item>
<item>来宾item>
<item>崇左item>
string-array>
<string-array name="海南">
<item>-城市-item>
<item>海口item>
<item>三亚item>
<item>三沙item>
<item>五指山item>
<item>琼海item>
<item>儋州item>
<item>文昌item>
<item>万宁item>
<item>东方item>
<item>定安item>
<item>屯昌item>
<item>澄迈item>
<item>临高item>
<item>白沙item>
<item>昌江item>
<item>乐东item>
<item>陵水item>
<item>保亭item>
<item>琼中item>
string-array>
<string-array name="重庆">
<item>-城市-item>
<item>万州item>
<item>涪陵item>
<item>渝中item>
<item>大渡口item>
<item>江北item>
<item>沙坪坝item>
<item>九龙坡item>
<item>南岸item>
<item>北碚item>
<item>两江新区item>
<item>万盛item>
<item>双桥item>
<item>渝北item>
<item>巴南item>
<item>长寿item>
<item>綦江item>
<item>潼南item>
<item>铜梁item>
<item>大足item>
<item>荣昌item>
<item>璧山item>
<item>梁平item>
<item>城口item>
<item>丰都item>
<item>垫江item>
<item>武隆item>
<item>忠县item>
<item>开县item>
<item>云阳item>
<item>奉节item>
<item>巫山item>
<item>巫溪item>
<item>黔江item>
<item>石柱item>
<item>秀山item>
<item>酉阳item>
<item>彭水item>
<item>江津item>
<item>合川item>
<item>永川item>
<item>南川item>
string-array>
<string-array name="四川">
<item>-城市-item>
<item>成都item>
<item>自贡item>
<item>攀枝花item>
<item>泸州item>
<item>德阳item>
<item>绵阳item>
<item>广元item>
<item>遂宁item>
<item>内江item>
<item>乐山item>
<item>南充item>
<item>眉山item>
<item>宜宾item>
<item>广安item>
<item>达州item>
<item>雅安item>
<item>巴中item>
<item>资阳item>
<item>阿坝item>
<item>甘孜item>
<item>凉山item>
string-array>
<string-array name="贵州">
<item>-城市-item>
<item>贵阳item>
<item>六盘水item>
<item>遵义item>
<item>安顺item>
<item>铜仁item>
<item>黔西南item>
<item>毕节item>
<item>黔东南item>
<item>黔南item>
string-array>
<string-array name="云南">
<item>-城市-item>
<item>昆明item>
<item>曲靖item>
<item>玉溪item>
<item>保山item>
<item>昭通item>
<item>丽江item>
<item>普洱item>
<item>临沧item>
<item>楚雄item>
<item>红河item>
<item>文山item>
<item>西双版纳item>
<item>大理item>
<item>德宏item>
<item>怒江item>
<item>迪庆item>
string-array>
<string-array name="西藏">
<item>-城市-item>
<item>拉萨item>
<item>昌都item>
<item>山南item>
<item>日喀则item>
<item>那曲item>
<item>阿里item>
<item>林芝item>
string-array>
<string-array name="陕西">
<item>-城市-item>
<item>西安item>
<item>铜川item>
<item>宝鸡item>
<item>咸阳item>
<item>渭南item>
<item>延安item>
<item>汉中item>
<item>榆林item>
<item>安康item>
<item>商洛item>
string-array>
<string-array name="甘肃">
<item>-城市-item>
<item>兰州市item>
<item>嘉峪关item>
<item>金昌item>
<item>白银item>
<item>天水item>
<item>武威item>
<item>张掖item>
<item>平凉item>
<item>酒泉item>
<item>庆阳item>
<item>定西item>
<item>陇南item>
<item>临夏item>
<item>甘南item>
string-array>
<string-array name="青海">
<item>-城市-item>
<item>西宁item>
<item>海东item>
<item>海北item>
<item>黄南item>
<item>海南item>
<item>果洛item>
<item>玉树item>
<item>海西item>
string-array>
<string-array name="宁夏">
<item>-城市-item>
<item>银川item>
<item>石嘴山item>
<item>吴忠item>
<item>固原item>
<item>中卫item>
string-array>
<string-array name="新疆">
<item>-城市-item>
<item>乌鲁木齐item>
<item>克拉玛依item>
<item>吐鲁番item>
<item>哈密item>
<item>昌吉item>
<item>博尔塔拉item>
<item>巴音郭楞item>
<item>阿克苏item>
<item>克孜勒苏item>
<item>喀什item>
<item>和田item>
<item>伊犁item>
<item>塔城item>
<item>阿勒泰item>
<item>石河子item>
<item>阿拉尔item>
<item>图木舒克item>
<item>五家渠item>
<item>北屯item>
string-array>
<string-array name="台湾">
<item>-城市-item>
<item>台北市item>
<item>高雄市item>
<item>基隆市item>
<item>台中市item>
<item>台南市item>
<item>新竹市item>
<item>嘉义市item>
<item>台北县item>
<item>宜兰县item>
<item>桃园县item>
<item>新竹县item>
<item>苗栗县item>
<item>台中县item>
<item>彰化县item>
<item>南投县item>
<item>云林县item>
<item>嘉义县item>
<item>台南县item>
<item>高雄县item>
<item>屏东县item>
<item>台东县item>
<item>花莲县item>
<item>澎湖县item>
string-array>
<string-array name="香港">
<item>-城市-item>
<item>中西区item>
<item>东区item>
<item>九龙城区item>
<item>观塘区item>
<item>南区item>
<item>深水埗区item>
<item>黄大仙区item>
<item>湾仔区item>
<item>油尖旺区item>
<item>离岛区item>
<item>葵青区item>
<item>北区item>
<item>西贡区item>
<item>沙田区item>
<item>屯门区item>
<item>大埔区item>
<item>荃湾区item>
<item>元朗区item>
string-array>
<string-array name="澳门">
<item>-城市-item>
<item>花地玛堂区item>
<item>圣安多尼堂区item>
<item>大堂区item>
<item>望德堂区item>
<item>风顺堂区item>
<item>氹仔item>
<item>路环item>
string-array>