省市区选择框

1.简介

在项目里遇到了地区选择,并非在一个选择框中选择,产品要求显示三个选择框分别选择,现记录下实现过程,以备后用。

2.效果图
area_select.png

选择省


province_select.png

选择市

city_select.png

选择区县

county_select.png
3.实现

根据数据结构,构建实体类

/**
     * area_id_parent : 0
     * id : 4
     * name : 河北省
     * second : [{"area_id_parent":"4","id":"73","name":"石家庄市","three":[{"area_id_parent":"73","id":"74","name":"长安区"},{"area_id_parent":"73","id":"75","name":"桥东区"},{"area_id_parent":"73","id":"76","name":"桥西区"},{"area_id_parent":"73","id":"77","name":"新华区"},{"area_id_parent":"73","id":"78","name":"井陉矿区"},{"area_id_parent":"73","id":"79","name":"裕华区"},{"area_id_parent":"73","id":"80","name":"井陉县"},{"area_id_parent":"73","id":"81","name":"正定县"},{"area_id_parent":"73","id":"82","name":"栾城县"},{"area_id_parent":"73","id":"83","name":"行唐县"},{"area_id_parent":"73","id":"84","name":"灵寿县"},{"area_id_parent":"73","id":"85","name":"高邑县"},{"area_id_parent":"73","id":"86","name":"深泽县"},{"area_id_parent":"73","id":"87","name":"赞皇县"},{"area_id_parent":"73","id":"88","name":"无极县"},{"area_id_parent":"73","id":"89","name":"平山县"},{"area_id_parent":"73","id":"90","name":"元氏县"},{"area_id_parent":"73","id":"91","name":"赵县"},{"area_id_parent":"73","id":"92","name":"辛集市"},{"area_id_parent":"73","id":"93","name":"藁城市"},{"area_id_parent":"73","id":"94","name":"晋州市"},{"area_id_parent":"73","id":"95","name":"新乐市"},{"area_id_parent":"73","id":"96","name":"鹿泉市"}]},{"area_id_parent":"4","id":"97","name":"唐山市","three":[{"area_id_parent":"97","id":"98","name":"路南区"},{"area_id_parent":"97","id":"99","name":"路北区"},{"area_id_parent":"97","id":"100","name":"古冶区"},{"area_id_parent":"97","id":"101","name":"开平区"},{"area_id_parent":"97","id":"102","name":"丰南区"},{"area_id_parent":"97","id":"103","name":"丰润区"},{"area_id_parent":"97","id":"104","name":"滦县"},{"area_id_parent":"97","id":"105","name":"滦南县"},{"area_id_parent":"97","id":"106","name":"乐亭县"},{"area_id_parent":"97","id":"107","name":"迁西县"},{"area_id_parent":"97","id":"108","name":"玉田县"},{"area_id_parent":"97","id":"109","name":"唐海县"},{"area_id_parent":"97","id":"110","name":"遵化市"},{"area_id_parent":"97","id":"111","name":"迁安市"}]},{"area_id_parent":"4","id":"112","name":"秦皇岛市","three":[{"area_id_parent":"112","id":"113","name":"海港区"},{"area_id_parent":"112","id":"114","name":"山海关区"},{"area_id_parent":"112","id":"115","name":"北戴河区"},{"area_id_parent":"112","id":"116","name":"青龙满族自治县"},{"area_id_parent":"112","id":"117","name":"昌黎县"},{"area_id_parent":"112","id":"118","name":"抚宁县"},{"area_id_parent":"112","id":"119","name":"卢龙县"}]},{"area_id_parent":"4","id":"120","name":"邯郸市","three":[{"area_id_parent":"120","id":"121","name":"邯山区"},{"area_id_parent":"120","id":"122","name":"丛台区"},{"area_id_parent":"120","id":"123","name":"复兴区"},{"area_id_parent":"120","id":"124","name":"峰峰矿区"},{"area_id_parent":"120","id":"125","name":"邯郸县"},{"area_id_parent":"120","id":"126","name":"临漳县"},{"area_id_parent":"120","id":"127","name":"成安县"},{"area_id_parent":"120","id":"128","name":"大名县"},{"area_id_parent":"120","id":"129","name":"涉县"},{"area_id_parent":"120","id":"130","name":"磁县"},{"area_id_parent":"120","id":"131","name":"肥乡县"},{"area_id_parent":"120","id":"132","name":"永年县"},{"area_id_parent":"120","id":"133","name":"邱县"},{"area_id_parent":"120","id":"134","name":"鸡泽县"},{"area_id_parent":"120","id":"135","name":"广平县"},{"area_id_parent":"120","id":"136","name":"馆陶县"},{"area_id_parent":"120","id":"137","name":"魏县"},{"area_id_parent":"120","id":"138","name":"曲周县"},{"area_id_parent":"120","id":"139","name":"武安市"}]},{"area_id_parent":"4","id":"140","name":"邢台市","three":[{"area_id_parent":"140","id":"141","name":"桥东区"},{"area_id_parent":"140","id":"142","name":"桥西区"},{"area_id_parent":"140","id":"143","name":"邢台县"},{"area_id_parent":"140","id":"144","name":"临城县"},{"area_id_parent":"140","id":"145","name":"内丘县"},{"area_id_parent":"140","id":"146","name":"柏乡县"},{"area_id_parent":"140","id":"147","name":"隆尧县"},{"area_id_parent":"140","id":"148","name":"任县"},{"area_id_parent":"140","id":"149","name":"南和县"},{"area_id_parent":"140","id":"150","name":"宁晋县"},{"area_id_parent":"140","id":"151","name":"巨鹿县"},{"area_id_parent":"140","id":"152","name":"新河县"},{"area_id_parent":"140","id":"153","name":"广宗县"},{"area_id_parent":"140","id":"154","name":"平乡县"},{"area_id_parent":"140","id":"155","name":"威县"},{"area_id_parent":"140","id":"156","name":"清河县"},{"area_id_parent":"140","id":"157","name":"临西县"},{"area_id_parent":"140","id":"158","name":"南宫市"},{"area_id_parent":"140","id":"159","name":"沙河市"}]},{"area_id_parent":"4","id":"160","name":"保定市","three":[{"area_id_parent":"160","id":"161","name":"新市区"},{"area_id_parent":"160","id":"162","name":"北市区"},{"area_id_parent":"160","id":"163","name":"南市区"},{"area_id_parent":"160","id":"164","name":"满城县"},{"area_id_parent":"160","id":"165","name":"清苑县"},{"area_id_parent":"160","id":"166","name":"涞水县"},{"area_id_parent":"160","id":"167","name":"阜平县"},{"area_id_parent":"160","id":"168","name":"徐水县"},{"area_id_parent":"160","id":"169","name":"定兴县"},{"area_id_parent":"160","id":"170","name":"唐县"},{"area_id_parent":"160","id":"171","name":"高阳县"},{"area_id_parent":"160","id":"172","name":"容城县"},{"area_id_parent":"160","id":"173","name":"涞源县"},{"area_id_parent":"160","id":"174","name":"望都县"},{"area_id_parent":"160","id":"175","name":"安新县"},{"area_id_parent":"160","id":"176","name":"易县"},{"area_id_parent":"160","id":"177","name":"曲阳县"},{"area_id_parent":"160","id":"178","name":"蠡县"},{"area_id_parent":"160","id":"179","name":"顺平县"},{"area_id_parent":"160","id":"180","name":"博野县"},{"area_id_parent":"160","id":"181","name":"雄县"},{"area_id_parent":"160","id":"182","name":"涿州市"},{"area_id_parent":"160","id":"183","name":"定州市"},{"area_id_parent":"160","id":"184","name":"安国市"},{"area_id_parent":"160","id":"185","name":"高碑店市"}]},{"area_id_parent":"4","id":"186","name":"张家口市","three":[{"area_id_parent":"186","id":"187","name":"桥东区"},{"area_id_parent":"186","id":"188","name":"桥西区"},{"area_id_parent":"186","id":"189","name":"宣化区"},{"area_id_parent":"186","id":"190","name":"下花园区"},{"area_id_parent":"186","id":"191","name":"宣化县"},{"area_id_parent":"186","id":"192","name":"张北县"},{"area_id_parent":"186","id":"193","name":"康保县"},{"area_id_parent":"186","id":"194","name":"沽源县"},{"area_id_parent":"186","id":"195","name":"尚义县"},{"area_id_parent":"186","id":"196","name":"蔚县"},{"area_id_parent":"186","id":"197","name":"阳原县"},{"area_id_parent":"186","id":"198","name":"怀安县"},{"area_id_parent":"186","id":"199","name":"万全县"},{"area_id_parent":"186","id":"200","name":"怀来县"},{"area_id_parent":"186","id":"201","name":"涿鹿县"},{"area_id_parent":"186","id":"202","name":"赤城县"},{"area_id_parent":"186","id":"203","name":"崇礼县"}]},{"area_id_parent":"4","id":"204","name":"承德市","three":[{"area_id_parent":"204","id":"205","name":"双桥区"},{"area_id_parent":"204","id":"206","name":"双滦区"},{"area_id_parent":"204","id":"207","name":"鹰手营子矿区"},{"area_id_parent":"204","id":"208","name":"承德县"},{"area_id_parent":"204","id":"209","name":"兴隆县"},{"area_id_parent":"204","id":"210","name":"平泉县"},{"area_id_parent":"204","id":"211","name":"滦平县"},{"area_id_parent":"204","id":"212","name":"隆化县"},{"area_id_parent":"204","id":"213","name":"丰宁满族自治县"},{"area_id_parent":"204","id":"214","name":"宽城满族自治县"},{"area_id_parent":"204","id":"215","name":"围场满族蒙古族自治县"}]},{"area_id_parent":"4","id":"216","name":"沧州市","three":[{"area_id_parent":"216","id":"217","name":"新华区"},{"area_id_parent":"216","id":"218","name":"运河区"},{"area_id_parent":"216","id":"219","name":"沧县"},{"area_id_parent":"216","id":"220","name":"青县"},{"area_id_parent":"216","id":"221","name":"东光县"},{"area_id_parent":"216","id":"222","name":"海兴县"},{"area_id_parent":"216","id":"223","name":"盐山县"},{"area_id_parent":"216","id":"224","name":"肃宁县"},{"area_id_parent":"216","id":"225","name":"南皮县"},{"area_id_parent":"216","id":"226","name":"吴桥县"},{"area_id_parent":"216","id":"227","name":"献县"},{"area_id_parent":"216","id":"228","name":"孟村回族自治县"},{"area_id_parent":"216","id":"229","name":"泊头市"},{"area_id_parent":"216","id":"230","name":"任丘市"},{"area_id_parent":"216","id":"231","name":"黄骅市"},{"area_id_parent":"216","id":"232","name":"河间市"}]},{"area_id_parent":"4","id":"233","name":"廊坊市","three":[{"area_id_parent":"233","id":"234","name":"安次区"},{"area_id_parent":"233","id":"235","name":"广阳区"},{"area_id_parent":"233","id":"236","name":"固安县"},{"area_id_parent":"233","id":"237","name":"永清县"},{"area_id_parent":"233","id":"238","name":"香河县"},{"area_id_parent":"233","id":"239","name":"大城县"},{"area_id_parent":"233","id":"240","name":"文安县"},{"area_id_parent":"233","id":"241","name":"大厂回族自治县"},{"area_id_parent":"233","id":"242","name":"霸州市"},{"area_id_parent":"233","id":"243","name":"三河市"}]},{"area_id_parent":"4","id":"244","name":"衡水市","three":[{"area_id_parent":"244","id":"245","name":"桃城区"},{"area_id_parent":"244","id":"246","name":"枣强县"},{"area_id_parent":"244","id":"247","name":"武邑县"},{"area_id_parent":"244","id":"248","name":"武强县"},{"area_id_parent":"244","id":"249","name":"饶阳县"},{"area_id_parent":"244","id":"250","name":"安平县"},{"area_id_parent":"244","id":"251","name":"故城县"},{"area_id_parent":"244","id":"252","name":"景县"},{"area_id_parent":"244","id":"253","name":"阜城县"},{"area_id_parent":"244","id":"254","name":"冀州市"},{"area_id_parent":"244","id":"255","name":"深州市"}]}]
     */
 private String area_id_parent;
    private String id;
    private String name;
    private ArrayList<SecondEntity> second;
    public String getArea_id_parent() {
        return area_id_parent;
    }
    public void setArea_id_parent(String area_id_parent) {
        this.area_id_parent = area_id_parent;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public ArrayList<SecondEntity> getSecond() {
        return second;
    }
    public void setSecond(ArrayList<SecondEntity> second) {
        this.second = second;
    }
    @Override
    public String toString() {
        return name;
    }
    public static class SecondEntity implements Serializable {
        private String area_id_parent;
        private String id;
        private String name;
        @Override
        public String toString() {
            return name;
        }
        private ArrayList<ThreeEntity> three;
        public String getArea_id_parent() {
            return area_id_parent;
        }
        public void setArea_id_parent(String area_id_parent) {
            this.area_id_parent = area_id_parent;
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public ArrayList<ThreeEntity> getThree() {
            return three;
        }
        public void setThree(ArrayList<ThreeEntity> three) {
            this.three = three;
        }
        public static class ThreeEntity implements Serializable {
            private String area_id_parent;
            private String id;
            private String name;
            public String getArea_id_parent() {
                return area_id_parent;
            }
            public void setArea_id_parent(String area_id_parent) {
                this.area_id_parent = area_id_parent;
            }
            @Override
            public String toString() {
                return name;
            }
            public String getId() {
                return id;
            }
            public void setId(String id) {
                this.id = id;
            }
            public String getName() {
                return name;
            }
            public void setName(String name) {
                this.name = name;
            }
        }
    }

在布局文件中使用TextView构建显示

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/tv_province"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/btn_boder_white_3dp"
            android:drawablePadding="6dp"
            android:drawableRight="@mipmap/arrow_down"
            android:gravity="center"
            android:paddingLeft="12dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:text="请选择省份"
            android:textColor="#333333"
            android:textSize="14dp" />

        <TextView
            android:id="@+id/tv_city"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="9dp"
            android:layout_weight="1"
            android:background="@drawable/btn_boder_white_3dp"
            android:drawablePadding="6dp"
            android:drawableRight="@mipmap/arrow_down"
            android:gravity="center"
            android:paddingLeft="12dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:text="请选择城市"
            android:textColor="#333333"
            android:textSize="14dp" />
        <TextView
            android:id="@+id/tv_county"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="9dp"
            android:layout_weight="1"
            android:background="@drawable/btn_boder_white_3dp"
            android:drawablePadding="6dp"
            android:drawableRight="@mipmap/arrow_down"
            android:gravity="center"
            android:paddingLeft="12dp"
            android:paddingRight="10dp"
            android:singleLine="true"
            android:text="请选择县区"
            android:textColor="#333333"
            android:textSize="14dp" />
    </LinearLayout>

定义变量

  public final static String HONG_KONG = "香港特别行政区";
    public final static String MA_KAO = "澳门特别行政区";
    private static final int HONG_KONG_OR_AO_MEN = -1;
//用于标识请求地区信息的类型,
    // 0表示进界面时的请求,
    // 1表示点击选择省之后的请求
    // 2表示点击选择市之后的请求
    // 3表示点击选择区之后的请求
    private int flag = 0;

点击选择省

tvProvince.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flag = 1;
                if (proviceEntityList == null) {
                    requestArea();//如果省级数据为null就请求数据
                } else {//有数据就直接显示
                    mHandler.sendEmptyMessage(SHOW_PROVINCE);
                }
            }
        });

这里数据使用模拟数据

private void requestArea(){
        String areaJson = "[{\"area_id_parent\":\"0\",\"id\":\"2\",\"name\":\"北京市\",\"second\":[{\"area_id_parent\":\"0\",\"id\":\"2\",\"name\":\"北京市\",\"three\":[{\"area_id_parent\":\"2\",\"id\":\"37\",\"name\":\"东城区\"},{\"area_id_parent\":\"2\",\"id\":\"38\",\"name\":\"西城区\"},{\"area_id_parent\":\"2\",\"id\":\"39\",\"name\":\"崇文区\"},{\"area_id_parent\":\"2\",\"id\":\"40\",\"name\":\"宣武区\"},{\"area_id_parent\":\"2\",\"id\":\"41\",\"name\":\"朝阳区\"},{\"area_id_parent\":\"2\",\"id\":\"42\",\"name\":\"丰台区\"},{\"area_id_parent\":\"2\",\"id\":\"43\",\"name\":\"石景山区\"},{\"area_id_parent\":\"2\",\"id\":\"44\",\"name\":\"海淀区\"},{\"area_id_parent\":\"2\",\"id\":\"45\",\"name\":\"门头沟区\"},{\"area_id_parent\":\"2\",\"id\":\"46\",\"name\":\"房山区\"},{\"area_id_parent\":\"2\",\"id\":\"47\",\"name\":\"通州区\"},{\"area_id_parent\":\"2\",\"id\":\"48\",\"name\":\"顺义区\"},{\"area_id_parent\":\"2\",\"id\":\"49\",\"name\":\"昌平区\"},{\"area_id_parent\":\"2\",\"id\":\"50\",\"name\":\"大兴区\"},{\"area_id_parent\":\"2\",\"id\":\"51\",\"name\":\"怀柔区\"},{\"area_id_parent\":\"2\",\"id\":\"52\",\"name\":\"平谷区\"},{\"area_id_parent\":\"2\",\"id\":\"53\",\"name\":\"密云县\"},{\"area_id_parent\":\"2\",\"id\":\"54\",\"name\":\"延庆县\"}]}]},\n" +
                "{\"area_id_parent\":\"0\",\"id\":\"3\",\"name\":\"天津市\",\"second\":[{\"area_id_parent\":\"0\",\"id\":\"3\",\"name\":\"天津市\",\"three\":[{\"area_id_parent\":\"3\",\"id\":\"55\",\"name\":\"和平区\"},{\"area_id_parent\":\"3\",\"id\":\"56\",\"name\":\"河东区\"},{\"area_id_parent\":\"3\",\"id\":\"57\",\"name\":\"河西区\"},{\"area_id_parent\":\"3\",\"id\":\"58\",\"name\":\"南开区\"},{\"area_id_parent\":\"3\",\"id\":\"59\",\"name\":\"河北区\"},{\"area_id_parent\":\"3\",\"id\":\"60\",\"name\":\"红桥区\"},{\"area_id_parent\":\"3\",\"id\":\"61\",\"name\":\"塘沽区\"},{\"area_id_parent\":\"3\",\"id\":\"62\",\"name\":\"汉沽区\"},{\"area_id_parent\":\"3\",\"id\":\"63\",\"name\":\"大港区\"},{\"area_id_parent\":\"3\",\"id\":\"64\",\"name\":\"东丽区\"},{\"area_id_parent\":\"3\",\"id\":\"65\",\"name\":\"西青区\"},{\"area_id_parent\":\"3\",\"id\":\"66\",\"name\":\"津南区\"},{\"area_id_parent\":\"3\",\"id\":\"67\",\"name\":\"北辰区\"},{\"area_id_parent\":\"3\",\"id\":\"68\",\"name\":\"武清区\"},{\"area_id_parent\":\"3\",\"id\":\"69\",\"name\":\"宝坻区\"},{\"area_id_parent\":\"3\",\"id\":\"70\",\"name\":\"宁河县\"},{\"area_id_parent\":\"3\",\"id\":\"71\",\"name\":\"静海县\"},{\"area_id_parent\":\"3\",\"id\":\"72\",\"name\":\"蓟县\"},{\"area_id_parent\":\"3\",\"id\":\"3190\",\"name\":\"滨海新区\"}]}]},\n" +
                "{\"area_id_parent\":\"0\",\"id\":\"4\",\"name\":\"河北省\",\"second\":[{\"area_id_parent\":\"4\",\"id\":\"73\",\"name\":\"石家庄市\",\"three\":[{\"area_id_parent\":\"73\",\"id\":\"74\",\"name\":\"长安区\"},{\"area_id_parent\":\"73\",\"id\":\"75\",\"name\":\"桥东区\"},{\"area_id_parent\":\"73\",\"id\":\"76\",\"name\":\"桥西区\"},{\"area_id_parent\":\"73\",\"id\":\"77\",\"name\":\"新华区\"},{\"area_id_parent\":\"73\",\"id\":\"78\",\"name\":\"井陉矿区\"},{\"area_id_parent\":\"73\",\"id\":\"79\",\"name\":\"裕华区\"},{\"area_id_parent\":\"73\",\"id\":\"80\",\"name\":\"井陉县\"},{\"area_id_parent\":\"73\",\"id\":\"81\",\"name\":\"正定县\"},{\"area_id_parent\":\"73\",\"id\":\"82\",\"name\":\"栾城县\"},{\"area_id_parent\":\"73\",\"id\":\"83\",\"name\":\"行唐县\"},{\"area_id_parent\":\"73\",\"id\":\"84\",\"name\":\"灵寿县\"},{\"area_id_parent\":\"73\",\"id\":\"85\",\"name\":\"高邑县\"},{\"area_id_parent\":\"73\",\"id\":\"86\",\"name\":\"深泽县\"},{\"area_id_parent\":\"73\",\"id\":\"87\",\"name\":\"赞皇县\"},{\"area_id_parent\":\"73\",\"id\":\"88\",\"name\":\"无极县\"},{\"area_id_parent\":\"73\",\"id\":\"89\",\"name\":\"平山县\"},{\"area_id_parent\":\"73\",\"id\":\"90\",\"name\":\"元氏县\"},{\"area_id_parent\":\"73\",\"id\":\"91\",\"name\":\"赵县\"},{\"area_id_parent\":\"73\",\"id\":\"92\",\"name\":\"辛集市\"},{\"area_id_parent\":\"73\",\"id\":\"93\",\"name\":\"藁城市\"},{\"area_id_parent\":\"73\",\"id\":\"94\",\"name\":\"晋州市\"},{\"area_id_parent\":\"73\",\"id\":\"95\",\"name\":\"新乐市\"},{\"area_id_parent\":\"73\",\"id\":\"96\",\"name\":\"鹿泉市\"}]},{\"area_id_parent\":\"4\",\"id\":\"97\",\"name\":\"唐山市\",\"three\":[{\"area_id_parent\":\"97\",\"id\":\"98\",\"name\":\"路南区\"},{\"area_id_parent\":\"97\",\"id\":\"99\",\"name\":\"路北区\"},{\"area_id_parent\":\"97\",\"id\":\"100\",\"name\":\"古冶区\"},{\"area_id_parent\":\"97\",\"id\":\"101\",\"name\":\"开平区\"},{\"area_id_parent\":\"97\",\"id\":\"102\",\"name\":\"丰南区\"},{\"area_id_parent\":\"97\",\"id\":\"103\",\"name\":\"丰润区\"},{\"area_id_parent\":\"97\",\"id\":\"104\",\"name\":\"滦县\"},{\"area_id_parent\":\"97\",\"id\":\"105\",\"name\":\"滦南县\"},{\"area_id_parent\":\"97\",\"id\":\"106\",\"name\":\"乐亭县\"},{\"area_id_parent\":\"97\",\"id\":\"107\",\"name\":\"迁西县\"},{\"area_id_parent\":\"97\",\"id\":\"108\",\"name\":\"玉田县\"},{\"area_id_parent\":\"97\",\"id\":\"109\",\"name\":\"唐海县\"},{\"area_id_parent\":\"97\",\"id\":\"110\",\"name\":\"遵化市\"},{\"area_id_parent\":\"97\",\"id\":\"111\",\"name\":\"迁安市\"}]},{\"area_id_parent\":\"4\",\"id\":\"112\",\"name\":\"秦皇岛市\",\"three\":[{\"area_id_parent\":\"112\",\"id\":\"113\",\"name\":\"海港区\"},{\"area_id_parent\":\"112\",\"id\":\"114\",\"name\":\"山海关区\"},{\"area_id_parent\":\"112\",\"id\":\"115\",\"name\":\"北戴河区\"},{\"area_id_parent\":\"112\",\"id\":\"116\",\"name\":\"青龙满族自治县\"},{\"area_id_parent\":\"112\",\"id\":\"117\",\"name\":\"昌黎县\"},{\"area_id_parent\":\"112\",\"id\":\"118\",\"name\":\"抚宁县\"},{\"area_id_parent\":\"112\",\"id\":\"119\",\"name\":\"卢龙县\"}]},{\"area_id_parent\":\"4\",\"id\":\"120\",\"name\":\"邯郸市\",\"three\":[{\"area_id_parent\":\"120\",\"id\":\"121\",\"name\":\"邯山区\"},{\"area_id_parent\":\"120\",\"id\":\"122\",\"name\":\"丛台区\"},{\"area_id_parent\":\"120\",\"id\":\"123\",\"name\":\"复兴区\"},{\"area_id_parent\":\"120\",\"id\":\"124\",\"name\":\"峰峰矿区\"},{\"area_id_parent\":\"120\",\"id\":\"125\",\"name\":\"邯郸县\"},{\"area_id_parent\":\"120\",\"id\":\"126\",\"name\":\"临漳县\"},{\"area_id_parent\":\"120\",\"id\":\"127\",\"name\":\"成安县\"},{\"area_id_parent\":\"120\",\"id\":\"128\",\"name\":\"大名县\"},{\"area_id_parent\":\"120\",\"id\":\"129\",\"name\":\"涉县\"},{\"area_id_parent\":\"120\",\"id\":\"130\",\"name\":\"磁县\"},{\"area_id_parent\":\"120\",\"id\":\"131\",\"name\":\"肥乡县\"},{\"area_id_parent\":\"120\",\"id\":\"132\",\"name\":\"永年县\"},{\"area_id_parent\":\"120\",\"id\":\"133\",\"name\":\"邱县\"},{\"area_id_parent\":\"120\",\"id\":\"134\",\"name\":\"鸡泽县\"},{\"area_id_parent\":\"120\",\"id\":\"135\",\"name\":\"广平县\"},{\"area_id_parent\":\"120\",\"id\":\"136\",\"name\":\"馆陶县\"},{\"area_id_parent\":\"120\",\"id\":\"137\",\"name\":\"魏县\"},{\"area_id_parent\":\"120\",\"id\":\"138\",\"name\":\"曲周县\"},{\"area_id_parent\":\"120\",\"id\":\"139\",\"name\":\"武安市\"}]},{\"area_id_parent\":\"4\",\"id\":\"140\",\"name\":\"邢台市\",\"three\":[{\"area_id_parent\":\"140\",\"id\":\"141\",\"name\":\"桥东区\"},{\"area_id_parent\":\"140\",\"id\":\"142\",\"name\":\"桥西区\"},{\"area_id_parent\":\"140\",\"id\":\"143\",\"name\":\"邢台县\"},{\"area_id_parent\":\"140\",\"id\":\"144\",\"name\":\"临城县\"},{\"area_id_parent\":\"140\",\"id\":\"145\",\"name\":\"内丘县\"},{\"area_id_parent\":\"140\",\"id\":\"146\",\"name\":\"柏乡县\"},{\"area_id_parent\":\"140\",\"id\":\"147\",\"name\":\"隆尧县\"},{\"area_id_parent\":\"140\",\"id\":\"148\",\"name\":\"任县\"},{\"area_id_parent\":\"140\",\"id\":\"149\",\"name\":\"南和县\"},{\"area_id_parent\":\"140\",\"id\":\"150\",\"name\":\"宁晋县\"},{\"area_id_parent\":\"140\",\"id\":\"151\",\"name\":\"巨鹿县\"},{\"area_id_parent\":\"140\",\"id\":\"152\",\"name\":\"新河县\"},{\"area_id_parent\":\"140\",\"id\":\"153\",\"name\":\"广宗县\"},{\"area_id_parent\":\"140\",\"id\":\"154\",\"name\":\"平乡县\"},{\"area_id_parent\":\"140\",\"id\":\"155\",\"name\":\"威县\"},{\"area_id_parent\":\"140\",\"id\":\"156\",\"name\":\"清河县\"},{\"area_id_parent\":\"140\",\"id\":\"157\",\"name\":\"临西县\"},{\"area_id_parent\":\"140\",\"id\":\"158\",\"name\":\"南宫市\"},{\"area_id_parent\":\"140\",\"id\":\"159\",\"name\":\"沙河市\"}]},{\"area_id_parent\":\"4\",\"id\":\"160\",\"name\":\"保定市\",\"three\":[{\"area_id_parent\":\"160\",\"id\":\"161\",\"name\":\"新市区\"},{\"area_id_parent\":\"160\",\"id\":\"162\",\"name\":\"北市区\"},{\"area_id_parent\":\"160\",\"id\":\"163\",\"name\":\"南市区\"},{\"area_id_parent\":\"160\",\"id\":\"164\",\"name\":\"满城县\"},{\"area_id_parent\":\"160\",\"id\":\"165\",\"name\":\"清苑县\"},{\"area_id_parent\":\"160\",\"id\":\"166\",\"name\":\"涞水县\"},{\"area_id_parent\":\"160\",\"id\":\"167\",\"name\":\"阜平县\"},{\"area_id_parent\":\"160\",\"id\":\"168\",\"name\":\"徐水县\"},{\"area_id_parent\":\"160\",\"id\":\"169\",\"name\":\"定兴县\"},{\"area_id_parent\":\"160\",\"id\":\"170\",\"name\":\"唐县\"},{\"area_id_parent\":\"160\",\"id\":\"171\",\"name\":\"高阳县\"},{\"area_id_parent\":\"160\",\"id\":\"172\",\"name\":\"容城县\"},{\"area_id_parent\":\"160\",\"id\":\"173\",\"name\":\"涞源县\"},{\"area_id_parent\":\"160\",\"id\":\"174\",\"name\":\"望都县\"},{\"area_id_parent\":\"160\",\"id\":\"175\",\"name\":\"安新县\"},{\"area_id_parent\":\"160\",\"id\":\"176\",\"name\":\"易县\"},{\"area_id_parent\":\"160\",\"id\":\"177\",\"name\":\"曲阳县\"},{\"area_id_parent\":\"160\",\"id\":\"178\",\"name\":\"蠡县\"},{\"area_id_parent\":\"160\",\"id\":\"179\",\"name\":\"顺平县\"},{\"area_id_parent\":\"160\",\"id\":\"180\",\"name\":\"博野县\"},{\"area_id_parent\":\"160\",\"id\":\"181\",\"name\":\"雄县\"},{\"area_id_parent\":\"160\",\"id\":\"182\",\"name\":\"涿州市\"},{\"area_id_parent\":\"160\",\"id\":\"183\",\"name\":\"定州市\"},{\"area_id_parent\":\"160\",\"id\":\"184\",\"name\":\"安国市\"},{\"area_id_parent\":\"160\",\"id\":\"185\",\"name\":\"高碑店市\"}]},{\"area_id_parent\":\"4\",\"id\":\"186\",\"name\":\"张家口市\",\"three\":[{\"area_id_parent\":\"186\",\"id\":\"187\",\"name\":\"桥东区\"},{\"area_id_parent\":\"186\",\"id\":\"188\",\"name\":\"桥西区\"},{\"area_id_parent\":\"186\",\"id\":\"189\",\"name\":\"宣化区\"},{\"area_id_parent\":\"186\",\"id\":\"190\",\"name\":\"下花园区\"},{\"area_id_parent\":\"186\",\"id\":\"191\",\"name\":\"宣化县\"},{\"area_id_parent\":\"186\",\"id\":\"192\",\"name\":\"张北县\"},{\"area_id_parent\":\"186\",\"id\":\"193\",\"name\":\"康保县\"},{\"area_id_parent\":\"186\",\"id\":\"194\",\"name\":\"沽源县\"},{\"area_id_parent\":\"186\",\"id\":\"195\",\"name\":\"尚义县\"},{\"area_id_parent\":\"186\",\"id\":\"196\",\"name\":\"蔚县\"},{\"area_id_parent\":\"186\",\"id\":\"197\",\"name\":\"阳原县\"},{\"area_id_parent\":\"186\",\"id\":\"198\",\"name\":\"怀安县\"},{\"area_id_parent\":\"186\",\"id\":\"199\",\"name\":\"万全县\"},{\"area_id_parent\":\"186\",\"id\":\"200\",\"name\":\"怀来县\"},{\"area_id_parent\":\"186\",\"id\":\"201\",\"name\":\"涿鹿县\"},{\"area_id_parent\":\"186\",\"id\":\"202\",\"name\":\"赤城县\"},{\"area_id_parent\":\"186\",\"id\":\"203\",\"name\":\"崇礼县\"}]},{\"area_id_parent\":\"4\",\"id\":\"204\",\"name\":\"承德市\",\"three\":[{\"area_id_parent\":\"204\",\"id\":\"205\",\"name\":\"双桥区\"},{\"area_id_parent\":\"204\",\"id\":\"206\",\"name\":\"双滦区\"},{\"area_id_parent\":\"204\",\"id\":\"207\",\"name\":\"鹰手营子矿区\"},{\"area_id_parent\":\"204\",\"id\":\"208\",\"name\":\"承德县\"},{\"area_id_parent\":\"204\",\"id\":\"209\",\"name\":\"兴隆县\"},{\"area_id_parent\":\"204\",\"id\":\"210\",\"name\":\"平泉县\"},{\"area_id_parent\":\"204\",\"id\":\"211\",\"name\":\"滦平县\"},{\"area_id_parent\":\"204\",\"id\":\"212\",\"name\":\"隆化县\"},{\"area_id_parent\":\"204\",\"id\":\"213\",\"name\":\"丰宁满族自治县\"},{\"area_id_parent\":\"204\",\"id\":\"214\",\"name\":\"宽城满族自治县\"},{\"area_id_parent\":\"204\",\"id\":\"215\",\"name\":\"围场满族蒙古族自治县\"}]},{\"area_id_parent\":\"4\",\"id\":\"216\",\"name\":\"沧州市\",\"three\":[{\"area_id_parent\":\"216\",\"id\":\"217\",\"name\":\"新华区\"},{\"area_id_parent\":\"216\",\"id\":\"218\",\"name\":\"运河区\"},{\"area_id_parent\":\"216\",\"id\":\"219\",\"name\":\"沧县\"},{\"area_id_parent\":\"216\",\"id\":\"220\",\"name\":\"青县\"},{\"area_id_parent\":\"216\",\"id\":\"221\",\"name\":\"东光县\"},{\"area_id_parent\":\"216\",\"id\":\"222\",\"name\":\"海兴县\"},{\"area_id_parent\":\"216\",\"id\":\"223\",\"name\":\"盐山县\"},{\"area_id_parent\":\"216\",\"id\":\"224\",\"name\":\"肃宁县\"},{\"area_id_parent\":\"216\",\"id\":\"225\",\"name\":\"南皮县\"},{\"area_id_parent\":\"216\",\"id\":\"226\",\"name\":\"吴桥县\"},{\"area_id_parent\":\"216\",\"id\":\"227\",\"name\":\"献县\"},{\"area_id_parent\":\"216\",\"id\":\"228\",\"name\":\"孟村回族自治县\"},{\"area_id_parent\":\"216\",\"id\":\"229\",\"name\":\"泊头市\"},{\"area_id_parent\":\"216\",\"id\":\"230\",\"name\":\"任丘市\"},{\"area_id_parent\":\"216\",\"id\":\"231\",\"name\":\"黄骅市\"},{\"area_id_parent\":\"216\",\"id\":\"232\",\"name\":\"河间市\"}]},{\"area_id_parent\":\"4\",\"id\":\"233\",\"name\":\"廊坊市\",\"three\":[{\"area_id_parent\":\"233\",\"id\":\"234\",\"name\":\"安次区\"},{\"area_id_parent\":\"233\",\"id\":\"235\",\"name\":\"广阳区\"},{\"area_id_parent\":\"233\",\"id\":\"236\",\"name\":\"固安县\"},{\"area_id_parent\":\"233\",\"id\":\"237\",\"name\":\"永清县\"},{\"area_id_parent\":\"233\",\"id\":\"238\",\"name\":\"香河县\"},{\"area_id_parent\":\"233\",\"id\":\"239\",\"name\":\"大城县\"},{\"area_id_parent\":\"233\",\"id\":\"240\",\"name\":\"文安县\"},{\"area_id_parent\":\"233\",\"id\":\"241\",\"name\":\"大厂回族自治县\"},{\"area_id_parent\":\"233\",\"id\":\"242\",\"name\":\"霸州市\"},{\"area_id_parent\":\"233\",\"id\":\"243\",\"name\":\"三河市\"}]},{\"area_id_parent\":\"4\",\"id\":\"244\",\"name\":\"衡水市\",\"three\":[{\"area_id_parent\":\"244\",\"id\":\"245\",\"name\":\"桃城区\"},{\"area_id_parent\":\"244\",\"id\":\"246\",\"name\":\"枣强县\"},{\"area_id_parent\":\"244\",\"id\":\"247\",\"name\":\"武邑县\"},{\"area_id_parent\":\"244\",\"id\":\"248\",\"name\":\"武强县\"},{\"area_id_parent\":\"244\",\"id\":\"249\",\"name\":\"饶阳县\"},{\"area_id_parent\":\"244\",\"id\":\"250\",\"name\":\"安平县\"},{\"area_id_parent\":\"244\",\"id\":\"251\",\"name\":\"故城县\"},{\"area_id_parent\":\"244\",\"id\":\"252\",\"name\":\"景县\"},{\"area_id_parent\":\"244\",\"id\":\"253\",\"name\":\"阜城县\"},{\"area_id_parent\":\"244\",\"id\":\"254\",\"name\":\"冀州市\"},{\"area_id_parent\":\"244\",\"id\":\"255\",\"name\":\"深州市\"}]}]},\n" +
                "{\"area_id_parent\":\"0\",\"id\":\"33\",\"name\":\"新疆维吾尔自治区\",\"second\":[{\"area_id_parent\":\"33\",\"id\":\"3080\",\"name\":\"乌鲁木齐市\",\"three\":[{\"area_id_parent\":\"3080\",\"id\":\"3081\",\"name\":\"天山区\"},{\"area_id_parent\":\"3080\",\"id\":\"3082\",\"name\":\"沙依巴克区\"},{\"area_id_parent\":\"3080\",\"id\":\"3083\",\"name\":\"新市区\"},{\"area_id_parent\":\"3080\",\"id\":\"3084\",\"name\":\"水磨沟区\"},{\"area_id_parent\":\"3080\",\"id\":\"3085\",\"name\":\"头屯河区\"},{\"area_id_parent\":\"3080\",\"id\":\"3086\",\"name\":\"达坂城区\"},{\"area_id_parent\":\"3080\",\"id\":\"3087\",\"name\":\"米东区\"},{\"area_id_parent\":\"3080\",\"id\":\"3088\",\"name\":\"乌鲁木齐县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3089\",\"name\":\"克拉玛依市\",\"three\":[{\"area_id_parent\":\"3089\",\"id\":\"3090\",\"name\":\"独山子区\"},{\"area_id_parent\":\"3089\",\"id\":\"3091\",\"name\":\"克拉玛依区\"},{\"area_id_parent\":\"3089\",\"id\":\"3092\",\"name\":\"白碱滩区\"},{\"area_id_parent\":\"3089\",\"id\":\"3093\",\"name\":\"乌尔禾区\"}]},{\"area_id_parent\":\"33\",\"id\":\"3094\",\"name\":\"吐鲁番地区\",\"three\":[{\"area_id_parent\":\"3094\",\"id\":\"3095\",\"name\":\"吐鲁番市\"},{\"area_id_parent\":\"3094\",\"id\":\"3096\",\"name\":\"鄯善县\"},{\"area_id_parent\":\"3094\",\"id\":\"3097\",\"name\":\"托克逊县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3098\",\"name\":\"哈密地区\",\"three\":[{\"area_id_parent\":\"3098\",\"id\":\"3099\",\"name\":\"哈密市\"},{\"area_id_parent\":\"3098\",\"id\":\"3100\",\"name\":\"巴里坤哈萨克自治县\"},{\"area_id_parent\":\"3098\",\"id\":\"3101\",\"name\":\"伊吾县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3102\",\"name\":\"昌吉回族自治州\",\"three\":[{\"area_id_parent\":\"3102\",\"id\":\"3103\",\"name\":\"昌吉市\"},{\"area_id_parent\":\"3102\",\"id\":\"3104\",\"name\":\"阜康市\"},{\"area_id_parent\":\"3102\",\"id\":\"3105\",\"name\":\"呼图壁县\"},{\"area_id_parent\":\"3102\",\"id\":\"3106\",\"name\":\"玛纳斯县\"},{\"area_id_parent\":\"3102\",\"id\":\"3107\",\"name\":\"奇台县\"},{\"area_id_parent\":\"3102\",\"id\":\"3108\",\"name\":\"吉木萨尔县\"},{\"area_id_parent\":\"3102\",\"id\":\"3109\",\"name\":\"木垒哈萨克自治县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3110\",\"name\":\"博尔塔拉蒙古自治州\",\"three\":[{\"area_id_parent\":\"3110\",\"id\":\"3111\",\"name\":\"博乐市\"},{\"area_id_parent\":\"3110\",\"id\":\"3112\",\"name\":\"精河县\"},{\"area_id_parent\":\"3110\",\"id\":\"3113\",\"name\":\"温泉县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3114\",\"name\":\"巴音郭楞蒙古自治州\",\"three\":[{\"area_id_parent\":\"3114\",\"id\":\"3115\",\"name\":\"库尔勒市\"},{\"area_id_parent\":\"3114\",\"id\":\"3116\",\"name\":\"轮台县\"},{\"area_id_parent\":\"3114\",\"id\":\"3117\",\"name\":\"尉犁县\"},{\"area_id_parent\":\"3114\",\"id\":\"3118\",\"name\":\"若羌县\"},{\"area_id_parent\":\"3114\",\"id\":\"3119\",\"name\":\"且末县\"},{\"area_id_parent\":\"3114\",\"id\":\"3120\",\"name\":\"焉耆回族自治县\"},{\"area_id_parent\":\"3114\",\"id\":\"3121\",\"name\":\"和静县\"},{\"area_id_parent\":\"3114\",\"id\":\"3122\",\"name\":\"和硕县\"},{\"area_id_parent\":\"3114\",\"id\":\"3123\",\"name\":\"博湖县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3124\",\"name\":\"阿克苏地区\",\"three\":[{\"area_id_parent\":\"3124\",\"id\":\"3125\",\"name\":\"阿克苏市\"},{\"area_id_parent\":\"3124\",\"id\":\"3126\",\"name\":\"温宿县\"},{\"area_id_parent\":\"3124\",\"id\":\"3127\",\"name\":\"库车县\"},{\"area_id_parent\":\"3124\",\"id\":\"3128\",\"name\":\"沙雅县\"},{\"area_id_parent\":\"3124\",\"id\":\"3129\",\"name\":\"新和县\"},{\"area_id_parent\":\"3124\",\"id\":\"3130\",\"name\":\"拜城县\"},{\"area_id_parent\":\"3124\",\"id\":\"3131\",\"name\":\"乌什县\"},{\"area_id_parent\":\"3124\",\"id\":\"3132\",\"name\":\"阿瓦提县\"},{\"area_id_parent\":\"3124\",\"id\":\"3133\",\"name\":\"柯坪县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3134\",\"name\":\"克孜勒苏柯尔克孜自治州\",\"three\":[{\"area_id_parent\":\"3134\",\"id\":\"3135\",\"name\":\"阿图什市\"},{\"area_id_parent\":\"3134\",\"id\":\"3136\",\"name\":\"阿克陶县\"},{\"area_id_parent\":\"3134\",\"id\":\"3137\",\"name\":\"阿合奇县\"},{\"area_id_parent\":\"3134\",\"id\":\"3138\",\"name\":\"乌恰县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3139\",\"name\":\"喀什地区\",\"three\":[{\"area_id_parent\":\"3139\",\"id\":\"3140\",\"name\":\"喀什市\"},{\"area_id_parent\":\"3139\",\"id\":\"3141\",\"name\":\"疏附县\"},{\"area_id_parent\":\"3139\",\"id\":\"3142\",\"name\":\"疏勒县\"},{\"area_id_parent\":\"3139\",\"id\":\"3143\",\"name\":\"英吉沙县\"},{\"area_id_parent\":\"3139\",\"id\":\"3144\",\"name\":\"泽普县\"},{\"area_id_parent\":\"3139\",\"id\":\"3145\",\"name\":\"莎车县\"},{\"area_id_parent\":\"3139\",\"id\":\"3146\",\"name\":\"叶城县\"},{\"area_id_parent\":\"3139\",\"id\":\"3147\",\"name\":\"麦盖提县\"},{\"area_id_parent\":\"3139\",\"id\":\"3148\",\"name\":\"岳普湖县\"},{\"area_id_parent\":\"3139\",\"id\":\"3149\",\"name\":\"伽师县\"},{\"area_id_parent\":\"3139\",\"id\":\"3150\",\"name\":\"巴楚县\"},{\"area_id_parent\":\"3139\",\"id\":\"3151\",\"name\":\"塔什库尔干塔吉克自治县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3152\",\"name\":\"和田地区\",\"three\":[{\"area_id_parent\":\"3152\",\"id\":\"3153\",\"name\":\"和田市\"},{\"area_id_parent\":\"3152\",\"id\":\"3154\",\"name\":\"和田县\"},{\"area_id_parent\":\"3152\",\"id\":\"3155\",\"name\":\"墨玉县\"},{\"area_id_parent\":\"3152\",\"id\":\"3156\",\"name\":\"皮山县\"},{\"area_id_parent\":\"3152\",\"id\":\"3157\",\"name\":\"洛浦县\"},{\"area_id_parent\":\"3152\",\"id\":\"3158\",\"name\":\"策勒县\"},{\"area_id_parent\":\"3152\",\"id\":\"3159\",\"name\":\"于田县\"},{\"area_id_parent\":\"3152\",\"id\":\"3160\",\"name\":\"民丰县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3161\",\"name\":\"伊犁哈萨克自治州\",\"three\":[{\"area_id_parent\":\"3161\",\"id\":\"3162\",\"name\":\"伊宁市\"},{\"area_id_parent\":\"3161\",\"id\":\"3163\",\"name\":\"奎屯市\"},{\"area_id_parent\":\"3161\",\"id\":\"3164\",\"name\":\"伊宁县\"},{\"area_id_parent\":\"3161\",\"id\":\"3165\",\"name\":\"察布查尔锡伯自治县\"},{\"area_id_parent\":\"3161\",\"id\":\"3166\",\"name\":\"霍城县\"},{\"area_id_parent\":\"3161\",\"id\":\"3167\",\"name\":\"巩留县\"},{\"area_id_parent\":\"3161\",\"id\":\"3168\",\"name\":\"新源县\"},{\"area_id_parent\":\"3161\",\"id\":\"3169\",\"name\":\"昭苏县\"},{\"area_id_parent\":\"3161\",\"id\":\"3170\",\"name\":\"特克斯县\"},{\"area_id_parent\":\"3161\",\"id\":\"3171\",\"name\":\"尼勒克县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3172\",\"name\":\"塔城地区\",\"three\":[{\"area_id_parent\":\"3172\",\"id\":\"3173\",\"name\":\"塔城市\"},{\"area_id_parent\":\"3172\",\"id\":\"3174\",\"name\":\"乌苏市\"},{\"area_id_parent\":\"3172\",\"id\":\"3175\",\"name\":\"额敏县\"},{\"area_id_parent\":\"3172\",\"id\":\"3176\",\"name\":\"沙湾县\"},{\"area_id_parent\":\"3172\",\"id\":\"3177\",\"name\":\"托里县\"},{\"area_id_parent\":\"3172\",\"id\":\"3178\",\"name\":\"裕民县\"},{\"area_id_parent\":\"3172\",\"id\":\"3179\",\"name\":\"和布克赛尔蒙古自治县\"}]},{\"area_id_parent\":\"33\",\"id\":\"3180\",\"name\":\"阿勒泰地区\",\"three\":[{\"area_id_parent\":\"3180\",\"id\":\"3181\",\"name\":\"阿勒泰市\"},{\"area_id_parent\":\"3180\",\"id\":\"3182\",\"name\":\"布尔津县\"},{\"area_id_parent\":\"3180\",\"id\":\"3183\",\"name\":\"富蕴县\"},{\"area_id_parent\":\"3180\",\"id\":\"3184\",\"name\":\"福海县\"},{\"area_id_parent\":\"3180\",\"id\":\"3185\",\"name\":\"哈巴河县\"},{\"area_id_parent\":\"3180\",\"id\":\"3186\",\"name\":\"青河县\"},{\"area_id_parent\":\"3180\",\"id\":\"3187\",\"name\":\"吉木乃县\"}]}]},{\"area_id_parent\":\"0\",\"id\":\"34\",\"name\":\"台湾省\"},{\"area_id_parent\":\"0\",\"id\":\"35\",\"name\":\"香港特别行政区\"},{\"area_id_parent\":\"0\",\"id\":\"36\",\"name\":\"澳门特别行政区\"}]";
        Type type = new TypeToken<ArrayList<AreaEntity>>(){}.getType();
        proviceEntityList = new Gson().fromJson(areaJson,type);

        if (flag == 1) {
            mHandler.sendEmptyMessage(SHOW_PROVINCE);
        } else if (flag == 2) {
            mHandler.sendEmptyMessage(SHOW_CITY);
        } else if (flag == 3) {
            mHandler.sendEmptyMessage(SHOW_STREET);
        }
    }

点击选择市

tvCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag == HONG_KONG_OR_AO_MEN) {//香港或者澳门是没有市和区县
                    return;
                }
                flag = 2;
                if (proviceEntityList == null) {
                    requestArea();
                } else {
                    mHandler.sendEmptyMessage(SHOW_CITY);
                }
            }
        });

点击选择区县

tvCounty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag == HONG_KONG_OR_AO_MEN) {
                    return;
                }

                flag = 3;
                if (proviceEntityList == null) {
                    requestArea();
                } else {
                    mHandler.sendEmptyMessage(SHOW_STREET);
                }
            }
        });

handler接收消息 处理操作

private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case SHOW_PROVINCE:
                    showProvince();
                    break;
                case SHOW_CITY:
                    showCity();
                    break;
                case SHOW_STREET:
                    showStreet();
                    break;
            }
        }
    };

UI显示

 private void showProvince() {
        AreaSelectDialog provinceDialog = new AreaSelectDialog(this,proviceEntityList,choosedProvince);
        provinceDialog.setmOnDialogChangedListener(new AreaSelectDialog.OnDialogChangedListener() {
            @Override
            public void onDialogChanged(String currentItem) {
                tvProvince.setText(currentItem);
                if (!TextUtils.isEmpty(choosedProvince) && choosedProvince.equals(currentItem)) {
                    if (!TextUtils.isEmpty(choosedCity)) {
                        tvCity.setText(choosedCity);
                    }
                    if (!TextUtils.isEmpty(choosedCounty)) {
                        tvCounty.setText(choosedCounty);
                    }
                } else {
                    if (HONG_KONG.equals(currentItem) || MA_KAO.equals(currentItem)) {
                        tvCity.setText("");
                        tvCounty.setText("");
                    } else {
                        tvCity.setText("请选择城市");
                        tvCounty.setText("请选择县区");
                    }
                }
            }
            @Override
            public void onBackPressed() {
            }
            @Override
            public void onDismissedListener(String currentItem) {
                if (!TextUtils.isEmpty(choosedProvince) && !choosedProvince.equals(currentItem)) {
                    choosedCity = "";
                    choosedCounty = "";
                    tvCity.setText("请选择城市");
                    tvCounty.setText("请选择县区");
                }
                if (HONG_KONG.equals(currentItem) || MA_KAO.equals(currentItem)) {
                    flag = HONG_KONG_OR_AO_MEN;
                    choosedCity = "";
                    choosedCounty = "";
                    tvCity.setText(choosedCity);
                    tvCounty.setText(choosedCounty);
                }
                choosedProvince = currentItem;
                tvProvince.setText(choosedProvince);
                if (flag == 2 || flag == 3) {
                    showCity();
                }
            }
        });
    }

 private void showCity() {
        if (TextUtils.isEmpty(choosedProvince)) {
            mHandler.sendEmptyMessage(SHOW_PROVINCE);
            return;
        }//如果省没选,那就让他去选省
        if (proviceEntityList == null) {
            requestArea();
        }
        for (AreaEntity areaEntity : proviceEntityList) {
            if (choosedProvince.equals(areaEntity.getName())) {
                cityEntityList = areaEntity.getSecond();
            }
        }
        AreaSelectDialog cityDialog = new AreaSelectDialog(this, cityEntityList, choosedCity);
        cityDialog.setmOnDialogChangedListener(new AreaSelectDialog.OnDialogChangedListener() {
            @Override
            public void onDialogChanged(String currentItem) {
                tvCity.setText(currentItem);
                if (!TextUtils.isEmpty(choosedCity) && choosedCity.equals(currentItem)) {
                    if (!TextUtils.isEmpty(choosedCounty)) {
                        tvCounty.setText(choosedCounty);
                    }
                } else {
                    tvCounty.setText("请选择县区");
                }
            }
            @Override
            public void onBackPressed() {
                flag = 0;
            }
            @Override
            public void onDismissedListener(String currentItem) {
                if (!TextUtils.isEmpty(choosedCity) && !choosedCity.equals(currentItem)) {
                    choosedCounty = "";
                    tvCounty.setText("请选择县区");
                }
                choosedCity = currentItem;
                tvCity.setText(choosedCity);
                if (flag == 3) {
                    mHandler.sendEmptyMessage(SHOW_STREET);
                }
            }
        });
    }

 private void showStreet() {
        //如果市没选,那就让他去选市
        if (TextUtils.isEmpty(choosedCity)) {
            mHandler.sendEmptyMessage(SHOW_CITY);
            return;
        }
        if (cityEntityList == null) {
            for (AreaEntity areaEntity : proviceEntityList) {
                if (choosedProvince.equals(areaEntity.getName())) {
                    cityEntityList = areaEntity.getSecond();
                }
            }
        }
        for (AreaEntity.SecondEntity secondEntity : cityEntityList) {
            if (choosedCity.equals(secondEntity.getName())) {
                StreetEntityList = secondEntity.getThree();
            }
        }
        AreaSelectDialog streetDialog = new AreaSelectDialog(this, StreetEntityList, choosedCounty);
        streetDialog.setmOnDialogChangedListener(new AreaSelectDialog.OnDialogChangedListener() {
            @Override
            public void onDialogChanged(String currentItem) {
                tvCounty.setText(currentItem);
            }
            @Override
            public void onBackPressed() {
                flag = 0;
            }
            @Override
            public void onDismissedListener(String currentItem) {
                choosedCounty = currentItem;
                tvCounty.setText(choosedCounty);
            }
        });
    }

贴出AreaSelectDialog代码 使用到了WheelView

public class AreaSelectDialog {
    private  ArrayList mList;
    private  String currentItem;
    private Context mContext;
    private AlertDialog mAlertDialog;
    private Window mWindow;
    private WheelView mWheel;
    private JSONArray dataArray = new JSONArray();
    public AreaSelectDialog(Context context, ArrayList mlist, String item){
        this.mContext = context;
        this.mList = mlist;
        this.currentItem = item;
        mAlertDialog = new AlertDialog.Builder(context, R.style.MyDialog).create();
        mAlertDialog.setCanceledOnTouchOutside(true);
        mAlertDialog.setCancelable(true);
        mAlertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode,
                                 KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_SEARCH) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        mAlertDialog.show();
        mAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (mOnDialogChangedListener != null &&!TextUtils.isEmpty(getCurrentItem())) {
                    mOnDialogChangedListener.onDismissedListener(getCurrentItem());
                }
            }
        });
        //设置dialog为屏幕宽度
        WindowManager.LayoutParams params = mAlertDialog.getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.FILL_PARENT;
        mAlertDialog.getWindow().setAttributes(params);
        // 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
        mWindow = mAlertDialog.getWindow();
        mWindow.setContentView(R.layout.dialog_choose_area);

        mAlertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if(keyCode == KeyEvent.KEYCODE_BACK){
                    if (mOnDialogChangedListener != null) {
                        mOnDialogChangedListener.onBackPressed();
                        mAlertDialog.cancel();
                        return true;
                    }
                }
                return false;
            }
        });
        RelativeLayout panel = (RelativeLayout) mAlertDialog.findViewById(R.id.lin_area);
        panel.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                mAlertDialog.dismiss();
                return false;
            }
        });
        try {
            initWheelView();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 初始化WheelView控件
     */
    private void initWheelView() throws Exception {
        //左侧列表
        mWheel = (WheelView) mWindow.findViewById(R.id.wv_area);
        mWheel.setVisibleItems(5);
        mWheel.setCyclic(false);
        mWheel.setAdapter(new ListWheelAdapter(mList, 5));
        if (TextUtils.isEmpty(currentItem)) {
            int leftIdx = dataArray.length() / 2;
            mWheel.setCurrentItem(leftIdx);
        }else{
            for (int i = 0; i < mList.size(); i++) {
                if(currentItem.equals(mList.get(i).toString())){
                    mWheel.setCurrentItem(i);
                    break;
                }
            }
        }
        mWheel.addChangingListener(new OnWheelChangedListener() {
            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                if (mOnDialogChangedListener != null) {
                    mOnDialogChangedListener.onDialogChanged(getCurrentItem());
                }
            }
        });
    }

    /**
     * 获取当前-数据对象
     *
     * @return
     */
    public String getCurrentItem() {

        if(mList == null){
            return "";
        }
        int leftPos = mWheel.getCurrentItem();
        Object item = mList.get(leftPos);
        return item.toString();
    }
    /**
     * 关闭对话框
     */
    public void dismiss() {
        mAlertDialog.dismiss();
    }
    /**
     * 未选择器-填充数据
     *
     * @param result
     * @throws Exception
     */
    private void initView(String result) throws Exception {

        JSONObject obj = new JSONObject(result);
        dataArray = obj.optJSONArray("data");
        initWheelView();
    }
    private OnDialogChangedListener mOnDialogChangedListener;
    public void setmOnDialogChangedListener(OnDialogChangedListener mOnDialogChangedListener) {
        this.mOnDialogChangedListener = mOnDialogChangedListener;
    }
    public interface OnDialogChangedListener {
        void onDialogChanged(String currentItem);
        void onBackPressed();
        void onDismissedListener(String currentItem);
    }
}

代码具体下载地址
http://download.csdn.net/detail/feibendexiaoma/9767025

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,172评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,346评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,788评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,299评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,409评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,467评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,476评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,262评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,699评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,994评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,167评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,827评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,499评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,149评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,387评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,028评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,055评论 2 352

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 171,951评论 25 707
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,383评论 0 17
  • —“在干嘛?” —“什么事? —“想你了呗,聊聊天” 总是会有一些人在你上学,上班的时候问你在干嘛,问你在不在,还...
    麻栗啊阅读 305评论 0 0
  • 好多天的雨和大雾,今天同样如此,离家的前半段还是阳光恰好,到公司的后半段就是大雾弥漫,总是不开警示灯和大灯是不行的...
    jimmyfool阅读 990评论 0 0
  • 我需要三件东西:爱情友谊和图书。然而这三者之间何其相通!炽热的爱情可以充实图书的内容,图书又是人们最忠实的朋友。 ...
    岚风的叶子阅读 188评论 0 0