Android省市县三级联动 真实项目抽出 调用只需3行代码 源码免积分下载

Posted 源于未知

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android省市县三级联动 真实项目抽出 调用只需3行代码 源码免积分下载相关的知识,希望对你有一定的参考价值。

写在前面:没想到短短一夜之间就有910次阅读量,迄今为止最高阅读量的一篇,小激动!

  • 项目源码:包含日期、省市县两种选择器[资源积分:0分] ,APK安装包下载,没有CSDN账户的的点此下载源码
  • fastjson自己复制博客里源码的小伙伴,注意导入fastjson框架哦!阿里巴巴出品的最快json解析框架
  • 日期选择器:效果图中的选择年月日的日期选择器
  • 任何问题,欢迎评论;源码下载不成功的留下邮箱;文章我还在维护,持续优化,有问题的小伙伴积极评论哈。

先上效果图: 样式可以修改xml文件


  • 省市县三级联动,选地址经常用到
  • 原生NumberPicker控件实现滑动,json数据解析使用fastjson框架
  • 使用简单:传入一个String[]数组,设置选择器的默认值,点击确认按钮,回调接口返回String[]数组,为重新选择的省市县
  • 随意修改:效果图中字体颜色布局等都可以修改,以保证与你的项目风格统一

把我源码里写好的java文件和xml文件拷到你的项目中,调用就这么简单:

 ChooseCityUtil cityUtil = new ChooseCityUtil();
        String[] oldCityArray = {"广东","深圳","福田"};
        cityUtil.createDialog(this, oldCityArray, new ChooseCityInterface() {
            @Override
            public void sure(String[] newCityArray) {
                //oldCityArray为传入的默认值 newCityArray为返回的结果
                tvCity.setText(newCityArray[0] + "-" + newCityArray[1] + "-" + newCityArray[2]);
            }
        });

-------------------------------------------------------- 我是分割线 --------------------------------------------------------

接下来看是如何实现的

布局文件activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@color/mainColor"
        android:gravity="center"
        android:text="选择器 Picker"
        android:textColor="@color/white"
        android:textSize="20sp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="城市设置:"
            android:textColor="#656565"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/tvCity"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:clickable="true"
            android:gravity="center"
            android:onClick="chooseCityDialog"
            android:text="广东-深圳-福田"
            android:textColor="#656565"
            android:textSize="18sp" />
    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:background="@color/gray" />

</LinearLayout>


对话框布局文件 dialog_choose_city.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"
    android:gravity="center"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#FFF">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <NumberPicker
                android:id="@+id/npProvince"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="省"
                android:textColor="#656565"
                android:textSize="18sp" />

            <NumberPicker
                android:id="@+id/npCity"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="市"
                android:textColor="#656565"
                android:textSize="18sp" />

            <NumberPicker
                android:id="@+id/npCounty"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text=""
                android:textColor="#656565"
                android:textSize="18sp" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:background="#EEEEEE"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tvCancel"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="取消"
                android:textColor="#656565"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/tvSure"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="确定"
                android:textColor="#656565"
                android:textSize="18sp" />
        </LinearLayout>

    </LinearLayout>


</LinearLayout>

接口类ChooseCityInterface.java

public interface ChooseCityInterface {
    public void sure(String[] newCityArray);
}

json对应实体类CityBean.java

public class CityBean {

    private String note;
    private List<Data> data;

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public List<Data> getData() {
        return data;
    }

    public void setData(List<Data> data) {
        this.data = data;
    }

    public static class Data {
        private String name;
        private List<City> city;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List<City> getCity() {
            return city;
        }

        public void setCity(List<City> city) {
            this.city = city;
        }

        public static class City {
            private String name;
            private List<String> county;

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public List<String> getCounty() {
                return county;
            }

            public void setCounty(List<String> county) {
                this.county = county;
            }
        }
    }
}
选择地址对话框工具类 ChooseCityUtil.java

public class ChooseCityUtil implements View.OnClickListener, NumberPicker.OnValueChangeListener {

    Context context;
    AlertDialog dialog;
    ChooseCityInterface cityInterface;
    NumberPicker npProvince, npCity, npCounty;
    TextView tvCancel, tvSure;
    String[] newCityArray = new String[3];
    CityBean bean;

    public void createDialog(Context context, String[] oldCityArray, ChooseCityInterface cityInterface) {
        this.context = context;
        this.cityInterface = cityInterface;
        bean = JSON.parseObject(CityData.getJson(), CityBean.class);
        newCityArray[0] = oldCityArray[0];
        newCityArray[1] = oldCityArray[1];
        newCityArray[2] = oldCityArray[2];

        dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_choose_city);
        //初始化控件
        tvCancel = (TextView) window.findViewById(R.id.tvCancel);
        tvSure = (TextView) window.findViewById(R.id.tvSure);
        tvCancel.setOnClickListener(this);
        tvSure.setOnClickListener(this);
        npProvince = (NumberPicker) window.findViewById(R.id.npProvince);
        npCity = (NumberPicker) window.findViewById(R.id.npCity);
        npCounty = (NumberPicker) window.findViewById(R.id.npCounty);
        setNomal();
        //省:设置选择器最小值、最大值、初始值
        String[] provinceArray = new String[bean.getData().size()];//初始化省数组
        for (int i = 0; i < provinceArray.length; i++) {//省数组填充数据
            provinceArray[i] = bean.getData().get(i).getName();
        }
        npProvince.setDisplayedValues(provinceArray);//设置选择器数据、默认值
        npProvince.setMinValue(0);
        npProvince.setMaxValue(provinceArray.length - 1);
        for (int i = 0; i < provinceArray.length; i++) {
            if (provinceArray[i].equals(newCityArray[0])) {
                npProvince.setValue(i);
                changeCity(i);//联动市数据
            }
        }
    }

    //根据省,联动市数据
    private void changeCity(int provinceTag) {
        List<CityBean.Data.City> cityList = bean.getData().get(provinceTag).getCity();
        String[] cityArray = new String[cityList.size()];
        for (int i = 0; i < cityArray.length; i++) {
            cityArray[i] = cityList.get(i).getName();
        }
        try {
            npCity.setMinValue(0);
            npCity.setMaxValue(cityArray.length - 1);
            npCity.setWrapSelectorWheel(false);
            npCity.setDisplayedValues(cityArray);//设置选择器数据、默认值
        } catch (Exception e) {
            npCity.setDisplayedValues(cityArray);//设置选择器数据、默认值
            npCity.setMinValue(0);
            npCity.setMaxValue(cityArray.length - 1);
            npCity.setWrapSelectorWheel(false);
        }
        for (int i = 0; i < cityArray.length; i++) {
            if (cityArray[i].equals(newCityArray[1])) {
                npCity.setValue(i);
                changeCounty(provinceTag, i);//联动县数据
                return;
            }
        }
        npCity.setValue(0);
        changeCounty(provinceTag, npCity.getValue());//联动县数据
    }

    //根据市,联动县数据
    private void changeCounty(int provinceTag, int cityTag) {
        List<String> countyList = bean.getData().get(provinceTag).getCity().get(cityTag).getCounty();
        String[] countyArray = new String[countyList.size()];
        for (int i = 0; i < countyArray.length; i++) {
            countyArray[i] = countyList.get(i).toString();
        }
        try {
            npCounty.setMinValue(0);
            npCounty.setMaxValue(countyArray.length - 1);
            npCounty.setWrapSelectorWheel(false);
            npCounty.setDisplayedValues(countyArray);//设置选择器数据、默认值
        } catch (Exception e) {
            npCounty.setDisplayedValues(countyArray);//设置选择器数据、默认值
            npCounty.setMinValue(0);
            npCounty.setMaxValue(countyArray.length - 1);
            npCounty.setWrapSelectorWheel(false);
        }
        for (int i = 0; i < countyArray.length; i++) {
            if (countyArray[i].equals(newCityArray[2])) {
                npCounty.setValue(i);
                return;
            }
        }
        npCounty.setValue(0);
    }

    //设置NumberPicker的分割线透明、字体颜色、设置监听
    private void setNomal() {
        //设置监听
        npProvince.setOnValueChangedListener(this);
        npCity.setOnValueChangedListener(this);
        npCounty.setOnValueChangedListener(this);
        //去除分割线
        setNumberPickerDividerColor(npProvince);
        setNumberPickerDividerColor(npCity);
        setNumberPickerDividerColor(npCounty);
        //设置字体颜色
        setNumberPickerTextColor(npProvince, context.getResources().getColor(R.color.mainColor));
        setNumberPickerTextColor(npCity, context.getResources().getColor(R.color.mainColor));
        setNumberPickerTextColor(npCounty, context.getResources().getColor(R.color.mainColor));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvCancel:
                dialog.dismiss();
                break;
            case R.id.tvSure:
                dialog.dismiss();
                cityInterface.sure(newCityArray);
                break;
        }
    }

    //选择器选择值监听
    @Override
    public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
        switch (picker.getId()) {
            case R.id.npProvince:
                List<CityBean.Data> dataList = bean.getData();
                newCityArray[0] = dataList.get(npProvince.getValue()).getName();
                changeCity(npProvince.getValue());
                newCityArray[1] = dataList.get(npProvince.getValue()).getCity().get(0).getName();
                newCityArray[2] = dataList.get(npProvince.getValue()).getCity().get(0).getCounty().get(0).toString();
                break;
            case R.id.npCity:
                List<CityBean.Data.City> cityList = bean.getData().get(npProvince.getValue()).getCity();
                newCityArray[1] = cityList.get(npCity.getValue()).getName();
                changeCounty(npProvince.getValue(), npCity.getValue());
                newCityArray[2] = cityList.get(npCity.getValue()).getCounty().get(0).toString();
                break;
            case R.id.npCounty:
                List<String> countyList = bean.getData().get(npProvince.getValue()).getCity().get(npCity.getValue()).getCounty();
                newCityArray[2] = countyList.get(npCounty.getValue()).toString();
                break;
        }
    }

    //设置分割线颜色
    private void setNumberPickerDividerColor(NumberPicker numberPicker) {
        NumberPicker picker = numberPicker;
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    //设置分割线的颜色值
                    pf.set(picker, new ColorDrawable(context.getResources().getColor(R.color.transparent)));// pf.set(picker, new Div)
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (Resources.NotFoundException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }

    //设置选择器字体颜色
    public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) {
        boolean result = false;
        final int count = numberPicker.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = numberPicker.getChildAt(i);
            if (child instanceof EditText) {
                try {
                    Field selectorWheelPaintField = numberPicker.getClass()
                            .getDeclaredField("mSelectorWheelPaint");
                    selectorWheelPaintField.setAccessible(true);
                    ((Paint) selectorWheelPaintField.get(numberPicker)).setColor(color);
                    ((EditText) child).setTextColor(color);
                    numberPicker.invalidate();
                    result = true;
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }
}

使用调用 MainActivity.java

public class MainActivity extends Activity {

    TextView tvCity;//城市

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    //初始化控件
    private void initView() {
        tvCity = (TextView) findViewById(R.id.tvCity);
    }

    //Choose Date 选择省市县
    public void chooseCityDialog(View view) {
        final ChooseCityUtil cityUtil = new ChooseCityUtil();
        String[] oldCityArray = tvCity.getText().toString().split("-");//将TextView上的文本分割成数组 当做默认值
        cityUtil.createDialog(this, oldCityArray, new ChooseCityInterface() {
            @Override
            public void sure(String[] newCityArray) {
                //oldCityArray为传入的默认值 newCityArray为返回的结果
                tvCity.setText(newCityArray[0] + "-" + newCityArray[1] + "-" + newCityArray[2]);
            }
        });
    }
}

颜色 colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="mainColor">#1BC47A</color>
    <color name="gray">#EEEEEE</color>
    <color name="black">#5E5E5E</color>
    <color name="white">#FFF</color>
    <color name="transparent">#00000000</color>
</resources>
省市县Json数据类 CityData.java

public class CityData {

    public static String getJson() {
        return "转译符看着太乱,把下面的json数据复制到这里,替换掉!";
    }
}
{
  "note": "全国省市县数据",
  "data": [
    {
      "name": "北京",
      "city": [
        {
          "name": "北京",
          "county": [
            "昌平",
            "朝阳",
            "大兴",
            "房山",
            "丰台",
            "海淀",
            "怀柔",
            "门头沟",
            "密云",
            "平谷",
            "石景山",
            "顺义",
            "通州",
            "宣武",
            "延庆"
          ]
        }
      ]
    },
    {
      "name": "安徽",
      "city": [
        {
          "name": "安庆",
          "county": [
            "大观",
            "怀宁",
            "潜山",
            "宿松",
            "太湖",
            "桐城",
            "望江",
            "宜秀",
            "迎江",
            "岳西",
            "枞阳"
          ]
        },
        {
          "name": "蚌埠",
          "county": [
            "蚌山",
            "固镇",
            "淮上",
            "怀远",
            "龙子湖",
            "五河",
            "禹会"
          ]
        },
        {
          "name": "亳州",
          "county": [
            "涡阳",
            "利辛",
            "蒙城",
            "谯城"
          ]
        },
        {
          "name": "巢湖",
          "county": [
            "含山",
            "和县",
            "居巢",
            "庐江",
            "无为"
          ]
        },
        {
          "name": "池州",
          "county": [
            "东至",
            "贵池",
            "青阳",
            "石台"
          ]
        },
        {
          "name": "滁州",
          "county": [
            "定远",
            "凤阳",
            "来安",
            "琅玡",
            "明光",
            "南谯",
            "全椒",
            "天长"
          ]
        },
        {
          "name": "阜阳",
          "county": [
            "阜南",
            "界首",
            "临泉",
            "太和",
            "颖东",
            "颖泉",
            "颍上",
            "颖州"
          ]
        },
        {
          "name": "合肥",
          "county": [
            "包河",
            "长丰",
            "肥东",
            "肥西",
            "庐阳",
            "蜀山",
            "瑶海"
          ]
        },
        {
          "name": "淮北",
          "county": [
            "杜集",
            "烈山",
            "濉溪",
            "相山"
          ]
        },
        {
          "name": "淮南",
          "county": [
            "八公山",
            "大通",
            "凤台",
            "潘集",
            "田家庵",
            "谢家集"
          ]
        },
        {
          "name": "黄山",
          "county": [
            "黄山",
            "徽州",
            "祁门",
            "歙县",
            "屯溪",
            "休宁",
            "黟县"
          ]
        },
        {
          "name": "六安",
          "county": [
            "霍邱",
            "霍山",
            "金安",
            "金寨",
            "寿县",
            "舒城",
            "裕安"
          ]
        },
        {
          "name": "马鞍山",
          "county": [
            "当涂",
            "花山",
            "金家庄",
            "雨山"
          ]
        },
        {
          "name": "宿州",
          "county": [
            "砀山",
            "灵璧",
            "泗县",
            "萧县",
            "埇桥"
          ]
        },
        {
          "name": "铜陵",
          "county": [
            "郊区",
            "狮子山",
            "铜官山",
            "铜陵"
          ]
        },
        {
          "name": "芜湖",
          "county": [
            "繁昌",
            "镜湖",
            "鸠江",
            "南陵",
            "三山",
            "芜湖县",
            "弋江"
          ]
        },
        {
          "name": "宣城",
          "county": [
            "广德",
            "绩溪",
            "旌德",
            "泾县",
            "郎溪",
            "宁国",
            "宣州"
          ]
        }
      ]
    },
    {
      "name": "澳门",
      "city": [
        {
          "name": "澳门半岛",
          "county": [
            "澳门半岛"
          ]
        },
        {
          "name": "氹仔岛",
          "county": [
            "氹仔岛"
          ]
        },
        {
          "name": "路环岛",
          "county": [
            "路环岛"
          ]
        }
      ]
    },
    {
      "name": "重庆",
      "city": [
        {
          "name": "重庆",
          "county": [
            "巴南",
            "北碚",
            "璧山",
            "长寿",
            "城口",
            "大渡口",
            "大足",
            "垫江",
            "丰都",
            "奉节",
            "涪陵",
            "合川",
            "江北",
            "江津",
            "九龙坡",
            "开县",
            "梁平",
            "南岸",
            "南川",
            "彭水",
            "綦江",
            "黔江",
            "荣昌",
            "沙坪坝",
            "石柱",
            "双桥",
            "铜梁",
            "潼南",
            "万盛",
            "万州",
            "巫山",
            "巫溪",
            "武隆",
            "秀山",
            "永川",
            "酉阳",
            "渝北",
            "渝中",
            "云阳",
            "忠县"
          ]
        }
      ]
    },
    {
      "name": "福建",
      "city": [
        {
          "name": "福州",
          "county": [
            "仓山",
            "长乐",
            "福清",
            "鼓楼",
            "晋安",
            "连江",
            "罗源",
            "马尾",
            "闽侯",
            "闽清",
            "平潭",
            "台江",
            "永泰"
          ]
        },
        {
          "name": "龙岩",
          "county": [
            "长汀",
            "连城",
            "上杭",
            "武平",
            "新罗",
            "永定",
            "漳平"
          ]
        },
        {
          "name": "南平",
          "county": [
            "光泽",
            "建瓯",
            "建阳",
            "浦城",
            "邵武",
            "顺昌",
            "松溪",
            "武夷山",
            "延平",
            "政和"
          ]
        },
        {
          "name": "宁德",
          "county": [
            "福安",
            "福鼎",
            "古田",
            "蕉城",
            "屏南",
            "寿宁",
            "霞浦",
            "柘荣",
            "周宁"
          ]
        },
        {
          "name": "莆田",
          "county": [
            "城厢",
            "涵江",
            "荔城",
            "仙游",
            "秀屿港"
          ]
        },
        {
          "name": "泉州",
          "county": [
            "安溪",
            "德化",
            "丰泽",
            "惠安",
            "金门",
            "晋江",
            "鲤城",
            "洛江",
            "南安",
            "泉港",
            "石狮",
            "永春"
          ]
        },
        {
          "name": "三明",
          "county": [
            "大田",
            "建宁",
            "将乐",
            "梅列",
            "明溪",
            "宁化",
            "清流",
            "三元",
            "沙县",
            "泰宁",
            "永安",
            "尤溪"
          ]
        },
        {
          "name": "厦门",
          "county": [
            "海沧",
            "湖里",
            "集美",
            "思明",
            "同安",
            "翔安"
          ]
        },
        {
          "name": "漳州",
          "county": [
            "长泰",
            "东山",
            "华安",
            "龙海",
            "龙文",
            "南靖",
            "平和",
            "芗城",
            "云霄",
            "漳浦",
            "诏安"
          ]
        }
      ]
    },
    {
      "name": "甘肃",
      "city": [
        {
          "name": "白银",
          "county": [
            "白银县",
            "会宁",
            "景泰",
            "靖远",
            "平川"
          ]
        },
        {
          "name": "定西",
          "county": [
            "安定",
            "临洮",
            "陇西",
            "岷县",
            "通渭",
            "渭源",
            "漳县"
          ]
        },
        {
          "name": "甘南",
          "county": [
            "迭部",
            "合作",
            "临潭",
            "碌曲",
            "玛曲",
            "夏河",
            "舟曲",
            "卓尼"
          ]
        },
        {
          "name": "嘉峪关",
          "county": [
            "嘉峪关"
          ]
        },
        {
          "name": "金昌",
          "county": [
            "金川",
            "永昌"
          ]
        },
        {
          "name": "酒泉",
          "county": [
            "阿克塞",
            "敦煌",
            "瓜州",
            "金塔",
            "肃北",
            "肃州",
            "玉门"
          ]
        },
        {
          "name": "兰州",
          "county": [
            "安宁",
            "城关",
            "皋兰",
            "红古",
            "七里河",
            "西固",
            "永登",
            "榆中"
          ]
        },
        {
          "name": "临夏",
          "county": [
            "东乡",
            "广河",
            "和政",
            "积石山",
            "康乐",
            "临夏市",
            "临夏县",
            "永靖"
          ]
        },
        {
          "name": "陇南",
          "county": [
            "成县",
            "宕昌",
            "徽县",
            "康县",
            "礼县",
            "两当",
            "文县",
            "武都",
            "西和"
          ]
        },
        {
          "name": "平凉",
          "county": [
            "崇信",
            "华亭",
            "泾川",
            "静宁",
            "崆峒",
            "灵台",
            "庄浪"
          ]
        },
        {
          "name": "庆阳",
          "county": [
            "合水",
            "华池",
            "环县",
            "宁县",
            "庆城",
            "西峰",
            "镇原",
            "正宁"
          ]
        },
        {
          "name": "天水",
          "county": [
            "甘谷",
            "麦积",
            "秦安",
            "秦州",
            "清水",
            "武山",
            "张家川"
          ]
        },
        {
          "name": "武威",
          "county": [
            "古浪",
            "凉州",
            "民勤",
            "天祝"
          ]
        },
        {
          "name": "张掖",
          "county": [
            "甘州",
            "高台",
            "临泽",
            "民乐",
            "山丹",
            "肃南"
          ]
        }
      ]
    },
    {
      "name": "广东",
      "city": [
        {
          "name": "潮州",
          "county": [
            "潮安",
            "饶平",
            "湘桥"
          ]
        },
        {
          "name": "东莞",
          "county": [
            "东莞县"
          ]
        },
        {
          "name": "佛山",
          "county": [
            "禅城",
            "高明",
            "南海",
            "三水",
            "顺德"
          ]
        },
        {
          "name": "广州",
          "county": [
            "白云",
            "从化",
            "海珠",
            "花都",
            "黄埔",
            "荔湾",
            "萝岗",
            "南沙",
            "番禺",
            "天河",
            "越秀",
            "增城"
          ]
        },
        {
          "name": "河源",
          "county": [
            "东源",
            "和平",
            "连平",
            "龙川",
            "源城",
            "紫金"
          ]
        },
        {
          "name": "惠州",
          "county": [
            "博罗",
            "惠城",
            "惠东",
            "惠阳",
            "龙门"
          ]
        },
        {
          "name": "江门",
          "county": [
            "恩平",
            "鹤山",
            "江海",
            "开平",
            "蓬江",
            "台山",
            "新会"
          ]
        },
        {
          "name": "揭阳",
          "county": [
            "惠来",
            "揭东",
            "揭西",
            "普宁",
            "榕城"
          ]
        },
        {
          "name": "茂名",
          "county": [
            "电白",
            "高州",
            "化州",
            "茂港",
            "茂南",
            "信宜"
          ]
        },
        {
          "name": "梅州",
          "county": [
            "大埔",
            "丰顺",
            "蕉岭",
            "梅县",
            "梅江",
            "平远",
            "五华",
            "兴宁"
          ]
        },
        {
          "name": "清远",
          "county": [
            "佛冈",
            "连南",
            "连山",
            "连州",
            "清城",
            "清新",
            "阳山",
            "英德"
          ]
        },
        {
          "name": "汕头",
          "county": [
            "潮南",
            "潮阳",
            "澄海",
            "濠江",
            "金平",
            "龙湖",
            "南澳"
          ]
        },
        {
          "name": "汕尾",
          "county": [
            "城区",
            "海丰",
            "陆丰",
            "陆河"
          ]
        },
        {
          "name": "韶关",
          "county": [
            "乐昌",
            "南雄",
            "曲江",
            "仁化",
            "乳源",
            "始兴",
            "翁源",
            "武江",
            "新丰",
            "浈江"
          ]
        },
        {
          "name": "深圳",
          "county": [
            "宝安",
            "福田",
            "龙岗",
            "罗湖",
            "南山",
            "盐田"
          ]
        },
        {
          "name": "阳江",
          "county": [
            "江城",
            "阳西",
            "阳春",
            "阳东"
          ]
        },
        {
          "name": "云浮",
          "county": [
            "罗定",
            "新兴",
            "郁南",
            "云安",
            "云城"
          ]
        },
        {
          "name": "湛江",
          "county": [
            "赤坎",
            "雷州",
            "廉江",
            "麻章",
            "坡头",
            "遂溪",
            "吴川",
            "霞山",
            "徐闻"
          ]
        },
        {
          "name": "肇庆",
          "county": [
            "德庆",
            "鼎湖",
            "端州",
            "封开",
            "高要",
            "广宁",
            "怀集",
            "四会"
          ]
        },
        {
          "name": "中山",
          "county": [
            "中山"
          ]
        },
        {
          "name": "珠海",
          "county": [
            "斗门",
            "金湾",
            "香洲"
          ]
        }
      ]
    },
    {
      "name": "广西",
      "city": [
        {
          "name": "百色",
          "county": [
            "德保",
            "靖西",
            "乐业",
            "凌云",
            "隆林",
            "那坡",
            "平果",
            "田东",
            "田林",
            "田阳",
            "西林",
            "右江"
          ]
        },
        {
          "name": "北海",
          "county": [
            "海城",
            "合浦",
            "铁山港",
            "银海"
          ]
        },
        {
          "name": "崇左",
          "county": [
            "大新",
            "扶绥",
            "江州",
            "宁明",
            "凭祥",
            "天等"
          ]
        },
        {
          "name": "防城港",
          "county": [
            "东兴",
            "防城",
            "港口",
            "上思"
          ]
        },
        {
          "name": "贵港",
          "county": [
            "港北",
            "港南",
            "桂平",
            "平南",
            "覃塘"
          ]
        },
        {
          "name": "桂林",
          "county": [
            "叠彩",
            "恭城",
            "灌阳",
            "荔浦",
            "灵川",
            "临桂",
            "龙胜",
            "平乐",
            "七星",
            "全州",
            "象山",
            "兴安",
            "秀峰",
            "雁山",
            "阳朔",
            "永福",
            "资源"
          ]
        },
        {
          "name": "河池",
          "county": [
            "巴马",
            "大化",
            "东兰",
            "都安",
            "凤山",
            "环江",
            "金城江",
            "罗城",
            "南丹",
            "天峨",
            "宜州"
          ]
        },
        {
          "name": "贺州",
          "county": [
            "八步",
            "富川",
            "昭平",
            "钟山"
          ]
        },
        {
          "name": "来宾",
          "county": [
            "合山",
            "金秀",
            "武宣",
            "象州",
            "忻城",
            "兴宾"
          ]
        },
        {
          "name": "柳州",
          "county": [
            "城中",
            "柳北",
            "柳城",
            "柳江",
            "柳南",
            "鹿寨",
            "融安",
            "融水",
            "三江",
            "鱼峰"
          ]
        },
        {
          "name": "南宁",
          "county": [
            "宾阳",
            "横县",
            "江南",
            "良庆",
            "隆安",
            "龙州",
            "马山",
            "青秀",
            "上林",
            "武鸣",
            "西乡塘",
            "兴宁",
            "邕宁"
          ]
        },
        {
          "name": "钦州",
          "county": [
            "灵山",
            "浦北",
            "钦北",
            "钦南"
          ]
        },
        {
          "name": "梧州",
          "county": [
            "苍梧",
            "岑溪",
            "长洲",
            "蝶山",
            "蒙山",
            "藤县",
            "万秀"
          ]
        },
        {
          "name": "玉林",
          "county": [
            "北流",
            "博白",
            "陆川",
            "容县",
            "兴业",
            "玉州"
          ]
        }
      ]
    },
    {
      "name": "贵州",
      "city": [
        {
          "name": "安顺",
          "county": [
            "关岭",
            "平坝",
            "普定",
            "西秀",
            "镇宁",
            "紫云"
          ]
        },
        {
          "name": "毕节市",
          "county": [
            "毕节县",
            "大方",
            "赫章",
            "金沙",
            "纳雍",
            "黔西",
            "威宁",
            "织金"
          ]
        },
        {
          "name": "贵阳",
          "county": [
            "白云",
            "花溪",
            "开阳",
            "南明",
            "清镇",
            "乌当",
            "息烽",
            "小河",
            "修文",
            "云岩"
          ]
        },
        {
          "name": "六盘水",
          "county": [
            "六枝特",
            "盘县",
            "水城",
            "钟山"
          ]
        },
        {
          "name": "黔东南",
          "county": [
            "岑巩",
            "从江",
            "丹寨",
            "黄平",
            "剑河",
            "锦屏",
            "凯里",
            "雷山",
            "黎平",
            "麻江",
            "榕江",
            "三穗",
            "施秉",
            "台江",
            "天柱",
            "镇远"
          ]
        },
        {
          "name": "黔南",
          "county": [
            "长顺",
            "独山",
            "都匀",
            "福泉",
            "贵定",
            "惠水",
            "荔波",
            "龙里",
            "罗甸",
            "平塘",
            "三都",
            "瓮安"
          ]
        },
        {
          "name": "黔西南",
          "county": [
            "安龙",
            "册亨",
            "普安",
            "晴隆",
            "望谟",
            "兴仁",
            "兴义",
            "贞丰"
          ]
        },
        {
          "name": "铜仁",
          "county": [
            "德江",
            "江口",
            "石阡",
            "思南",
            "松桃",
            "铜仁",
            "万山特",
            "印江",
            "玉屏"
          ]
        },
        {
          "name": "遵义",
          "county": [
            "赤水",
            "道真",
            "凤冈",
            "红花岗",
            "汇川",
            "湄潭",
            "仁怀",
            "绥阳",
            "桐梓",
            "务川",
            "习水",
            "余庆",
            "正安",
            "遵义县"
          ]
        }
      ]
    },
    {
      "name": "海南",
      "city": [
        {
          "name": "白沙",
          "county": [
            "白沙"
          ]
        },
        {
          "name": "保亭",
          "county": [
            "保亭"
          ]
        },
        {
          "name": "昌江",
          "county": [
            "昌江"
          ]
        },
        {
          "name": "澄迈",
          "county": [
            "澄迈"
          ]
        },
        {
          "name": "儋州",
          "county": [
            "儋州"
          ]
        },
        {
          "name": "定安",
          "county": [
            "定安"
          ]
        },
        {
          "name": "东方",
          "county": [
            "东方"
          ]
        },
        {
          "name": "海口",
          "county": [
            "龙华",
            "美兰",
            "琼山",
            "秀英"
          ]
        },
        {
          "name": "乐东",
          "county": [
            "乐东"
          ]
        },
        {
          "name": "临高",
          "county": [
            "临高"
          ]
        },
        {
          "name": "陵水",
          "county": [
            "陵水"
          ]
        },
        {
          "name": "琼海",
          "county": [
            "琼海"
          ]
        },
        {
          "name": "琼中",
          "county": [
            "琼中"
          ]
        },
        {
          "name": "三亚",
          "county": [
            "三亚"
          ]
        },
        {
          "name": "屯昌",
          "county": [
            "屯昌"
          ]
        },
        {
          "name": "万宁",
          "county": [
            "万宁"
          ]
        },
        {
          "name": "文昌",
          "county": [
            "文昌"
          ]
        },
        {
          "name": "五指山",
          "county": [
            "五指山"
          ]
        }
      ]
    },
    {
      "name": "河北",
      "city": [
        {
          "name": "保定",
          "county": [
            "安国",
            "安新",
            "北市区",
            "博野",
            "定兴",
            "定州",
            "阜平",
            "高碑店",
            "高阳",
            "涞水",
            "涞源",
            "蠡县",
            "满城",
            "南市区",
            "清苑",
            "曲阳",
            "容城",
            "顺平",
            "唐县",
            "望都",
            "新市",
            "雄县",
            "徐水",
            "易县",
            "涿州"
          ]
        },
        {
          "name": "沧州",
          "county": [
            "泊头",
            "沧县",
            "东光",
            "海兴",
            "河间",
            "黄骅",
            "孟村",
            "南皮",
            "青县",
            "任丘",
            "肃宁",
            "吴桥",
            "献县",
            "新华",
            "盐山",
            "运河"
          ]
        },
        {
          "name": "承德",
          "county": [
            "承德县",
            "丰宁",
            "宽城",
            "隆化",
            "滦平",
            "平泉",
            "双滦",
            "双桥",
            "围场",
            "兴隆",
            "鹰手营"
          ]
        },
        {
          "name": "邯郸",
          "county": [
            "磁县",
            "丛台",
            "大名",
            "肥乡",
            "峰峰",
            "复兴",
            "馆陶",
            "广平",
            "邯山",
            "鸡泽",
            "邱县",
            "曲周",
            "涉县",
            "魏县",
            "武安",
            "永年"
          ]
        },
        {
          "name": "衡水",
          "county": [
            "安平",
            "阜城",
            "故城",
            "冀州",
            "景县",
            "饶阳",
            "深州",
            "桃城",
            "武强",
            "武邑",
            "枣强"
          ]
        },
        {
          "name": "廊坊",
          "county": [
            "安次",
            "霸州",
            "大厂",
            "大城",
            "固安",
            "广阳",
            "三河",
            "文安",
            "香河",
            "永清"
          ]
        },
        {
          "name": "秦皇岛",
          "county": [
            "北戴河",
            "昌黎",
            "抚宁",
            "海港",
            "卢龙",
            "青龙",
            "山海关"
          ]
        },
        {
          "name": "石家庄",
          "county": [
            "长安",
            "高邑",
            "藁城",
            "晋州",
            "井陉矿区",
            "井陉",
            "灵寿",
            "鹿泉",
            "栾城",
            "平山",
            "桥东",
            "桥西",
            "深泽",
            "无极",
            "新华",
            "辛集",
            "新乐",
            "行唐",
            "裕华",
            "元氏",
            "赞皇",
            "赵县",
            "正定"
          ]
        },
        {
          "name": "唐山",
          "county": [
            "丰南",
            "丰润",
            "古冶",
            "开平",
            "乐亭",
            "路北",
            "路南",
            "滦南",
            "滦县",
            "迁安",
            "迁西",
            "唐海",
            "玉田",
            "遵化"
          ]
        },
        {
          "name": "邢台",
          "county": [
            "柏乡",
            "广宗",
            "巨鹿",
            "临城",
            "临西",
            "隆尧",
            "南宫",
            "南和",
            "内丘",
            "宁晋",
            "平乡",
            "桥东",
            "桥西",
            "清河",
            "任县",
            "沙河",
            "威县",
            "新河",
            "邢台县"
          ]
        },
        {
          "name": "张家口",
          "county": [
            "赤城",
            "崇礼",
            "沽源",
            "怀安",
            "怀来",
            "康保",
            "桥东",
            "桥西",
            "尚义",
            "万全",
            "蔚县",
            "下花园",
            "宣化区",
            "宣化县",
            "阳原",
            "张北",
            "涿鹿"
          ]
        }
      ]
    },
    {
      "name": "河南",
      "city": [
        {
          "name": "安阳",
          "county": [
            "安阳县",
            "北关",
            "滑县",
            "林州",
            "龙安",
            "内黄",
            "汤阴",
            "文峰",
            "殷都"
          ]
        },
        {
          "name": "鹤壁",
          "county": [
            "鹤山",
            "浚县",
            "淇滨",
            "淇县",
            "山城"
          ]
        },
        {
          "name": "焦作",
          "county": [
            "博爱",
            "解放",
            "马村",
            "孟州",
            "沁阳",
            "山阳",
            "温县",
            "武陟",
            "修武",
            "中站"
          ]
        },
        {
          "name": "开封",
          "county": [
            "鼓楼",
            "金明",
            "开封县",
            "兰考",
            "龙亭",
            "杞县",
            "顺河",
            "通许",
            "尉氏",
            "禹王台"
          ]
        },
        {
          "name": "漯河",
          "county": [
            "临颍",
            "舞阳",
            "郾城",
            "源汇",
            "召陵"
          ]
        },
        {
          "name": "洛阳",
          "county": [
            "瀍河",
            "吉利",
            "涧西",
            "老城",
            "栾川",
            "洛龙",
            "洛宁",
            "孟津",
            "汝阳",
            "嵩县",
            "西工",
            "新安",
            "偃师",
            "伊川",
            "宜阳"
          ]
        },
        {
          "name": "南阳",
          "county": [
            "邓州",
            "方城",
            "南召",
            "内乡",
            "社旗",
            "唐河",
            "桐柏",
            "宛城",
            "卧龙",
            "淅川",
            "西峡",
            "新野",
            "镇平"
          ]
        },
        {
          "name": "平顶山",
          "county": [
            "宝丰",
            "鲁山",
            "汝州",
            "石龙",
            "卫东",
            "舞钢",
            "新华",
            "叶县",
            "湛河",
            "郏县"
          ]
        },
        {
          "name": "濮阳",
          "county": [
            "范县",
            "华龙",
            "南乐",
            "濮阳县",
            "清丰",
            "台前"
          ]
        },
        {
          "name": "三门峡",
          "county": [
            "湖滨",
        

以上是关于Android省市县三级联动 真实项目抽出 调用只需3行代码 源码免积分下载的主要内容,如果未能解决你的问题,请参考以下文章

c# 做省市县联动

用vue实现省市县三级联动

省市区(县)三级联动

省市区(县)三级联动

Android省市区三级联动滚轮选择(真实项目中提取出来的组件)

django实现省市县三级联动