1.简介
在项目里遇到了地区选择,并非在一个选择框中选择,产品要求显示三个选择框分别选择,现记录下实现过程,以备后用。
2.效果图
选择省
选择市
选择区县
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