Android城市三级联动选择器

便捷、新颖的三级fdsafdsa联动城市选择器

/**

 * 城市Picker

 *

 * @author zihao

 *

 */

public class CityPicker extends LinearLayout {

    /** 滑动控件 */fdsaf

    private ScrollerNumberPicker provincePicker;

    private ScrollerNumberPicker cityPicker;

    private ScrollerNumberPicker counyPicker;

    /** 选择监听 */

    private OnSelectingListener onSelectingListener;

    /** 刷新界面 */

    private static final int REFRESH_VIEW = 0x001;

    /** 临时日期 */

    private int tempProvinceIndex = -1;

    private int temCityIndex = -1;

    private int tempCounyIndex = -1;

    private Context context;

    private List<cityinfo> province_list = new ArrayList<cityinfo>();

    private HashMap<string, list<cityinfo="">> city_map = new HashMap<string, list<cityinfo="">>();

    private HashMap<string, list<cityinfo="">> couny_map = new HashMap<string, list<cityinfo="">>();

    private CitycodeUtil citycodeUtil;

    private String city_code_string;

    private String city_string;

    public CityPicker(Context context, AttributeSet attrs) {

        super(context, attrs);

        this.context = context;

        getaddressinfo();

        // TODO Auto-generated constructor stub

    }

    public CityPicker(Context context) {

        super(context);

        this.context = context;

        getaddressinfo();

        // TODO Auto-generated constructor stub

    }

    // 获取城市信息

    private void getaddressinfo() {

        // TODO Auto-generated method stub

        // 读取城市信息string

        JSONParser parser = new JSONParser();

        String area_str = FileUtil.readAssets(context, "area.json");

        province_list = parser.getJSONParserResult(area_str, "area0");

        city_map = parser.getJSONParserResultArray(area_str, "area1");

        couny_map = parser.getJSONParserResultArray(area_str, "area2");

    }

    public static class JSONParser {

        public ArrayList<string> province_list_code = new ArrayList<string>();

        public ArrayList<string> city_list_code = new ArrayList<string>();

        public List<cityinfo> getJSONParserResult(String JSONString, String key) {

            List<cityinfo> list = new ArrayList<cityinfo>();

            JsonObject result = new JsonParser().parse(JSONString)

                    .getAsJsonObject().getAsJsonObject(key);

            Iterator<!--?--> iterator = result.entrySet().iterator();

            while (iterator.hasNext()) {

                @SuppressWarnings("unchecked")

                Map.Entry<string, jsonelement=""> entry = (Entry<string, jsonelement="">) iterator

                        .next();

                Cityinfo cityinfo = new Cityinfo();

                cityinfo.setCity_name(entry.getValue().getAsString());

                cityinfo.setId(entry.getKey());

                province_list_code.add(entry.getKey());

                list.add(cityinfo);

            }

            System.out.println(province_list_code.size());

            return list;

        }

        public HashMap<string, list<cityinfo="">> getJSONParserResultArray(

                String JSONString, String key) {

            HashMap<string, list<cityinfo="">> hashMap = new HashMap<string, list<cityinfo="">>();

            JsonObject result = new JsonParser().parse(JSONString)

                    .getAsJsonObject().getAsJsonObject(key);

            Iterator<!--?--> iterator = result.entrySet().iterator();

            while (iterator.hasNext()) {

                @SuppressWarnings("unchecked")

                Map.Entry<string, jsonelement=""> entry = (Entry<string, jsonelement="">) iterator

                        .next();

                List<cityinfo> list = new ArrayList<cityinfo>();

                JsonArray array = entry.getValue().getAsJsonArray();

                for (int i = 0; i < array.size(); i++) {

                    Cityinfo cityinfo = new Cityinfo();

                    cityinfo.setCity_name(array.get(i).getAsJsonArray().get(0)

                            .getAsString());

                    cityinfo.setId(array.get(i).getAsJsonArray().get(1)

                            .getAsString());

                    city_list_code.add(array.get(i).getAsJsonArray().get(1)

                            .getAsString());

                    list.add(cityinfo);

                }

                hashMap.put(entry.getKey(), list);

            }

            return hashMap;

        }

    }

源码包免费下载地址::【点击这里】

时间: 2024-10-12 00:03:08

Android城市三级联动选择器的相关文章

jquery 城市三级联动

js代码 /*城市三级联动 * @method cityChange * @param allProvince,allCity,allDistrict */ function cityChange(provinceN,cityN,districtN){ var all_province=""; for(var i=0;i<allCity.province.length;i++){ all_province+='<option name="province"

转: javascript实现全国城市三级联动菜单代码

<html> <head> <title>js全国城市三级联动菜单代码_B5教程网</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script LANGUAGE="JavaScript"> function Dsy() { this.Items = {}; } Dsy

城市三级联动 AJAX-原生js封装

话不多说我们先来一张效果图给大家看一下: html代码如下: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>城市三级联动 - citys-原生js封装</title> <link rel="shortcut icon" href="../public/image/favi

城市三级联动Springmvc+mysql

昨天我做了一个功能,就是一个简单的城市三级联动,现在贴上分享 是采用springmvc+mysql去做的,最后台的东西我就不写了,就是写控制层+HTML+Jquery的部分,以下是控制层 1 //获取省市区 2 @RequestMapping(value="province.do") 3 @ResponseBody 4 public Map<String, Object> province(HttpServletRequest request,HttpServletResp

时间和地域三级联动选择器(Android-PickerView-master)

先附上下载和效果展示地址 https://github.com/saiwu-bigkoo/Android-PickerView 之后说一下程序依赖后会遇到的问题Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found. 解决办法在Project下的build.gradle中添加两句 classpath 'com.github.dcendents:android-maven-gradle-plugin:1.

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

最近项目要做一个,类似淘宝手机客户端的,选择收货地址的三级联动滚动选择组件,下面是它的大致界面截图: 在IOS中有个叫UIPickerView的选择器,并且在dataSource中定义了UIPickerView的数据源和定制内容,所以用只要熟悉它的基本用法,要实现这么个三级联动滑动选择是挺简单的. 言归正传,今天讨论的是在Android里面如何来实现这么个效果,那么如何实现呢??? 相信部分童鞋首先想到的是android.widget.DatePicker和android.widget.Time

Js做的城市三级联动

这个是经常用到的,和大家分享一下 …… <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>飞

JS全国城市三级联动

HTML <select id="s_province" name="s_province"></select> <select id="s_city" name="s_city" ></select> <select id="s_county" name="s_county"></select> <scrip

ajax结合php简单的城市三级联动

//ajax代码 $('#pro').change(function () { var id = $(this).val(); if (id == 0) { $('#city').html('<option value="0">请选择城市</option>'); return false; } $.get('/bre/ajaxCity', {id: id}, function (data) { var html = ''; var area = ''; $.ea