Search in sources :

Example 1 with CityResult

use of com.wheelview.result.CityResult in project AndroidDevelop by 7449.

the class XmlManager method initProvinceDatas.

public void initProvinceDatas(AssetManager assetManager) {
    try {
        InputStream input = assetManager.open(PROVINCE_DATA);
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser parser = spf.newSAXParser();
        XmlParserHandler handler = new XmlParserHandler();
        parser.parse(input, handler);
        input.close();
        List<ProvinceResult> provinceList = handler.getDataList();
        // 初始化默认选中的省、市、区
        if (provinceList != null && !provinceList.isEmpty()) {
            mCurrentProviceName = provinceList.get(0).getName();
            List<CityResult> cityList = provinceList.get(0).getCityList();
            if (cityList != null && !cityList.isEmpty()) {
                mCurrentCityName = cityList.get(0).getName();
                List<DistrictResult> districtList = cityList.get(0).getDistrictList();
                mCurrentDistrictName = districtList.get(0).getName();
                mCurrentZipCode = districtList.get(0).getZipcode();
            }
            mProvinceDatas = new String[provinceList.size()];
            for (int i = 0; i < provinceList.size(); i++) {
                // 遍历所有省的数据
                mProvinceDatas[i] = provinceList.get(i).getName();
                cityList = provinceList.get(i).getCityList();
                String[] cityNames = new String[cityList.size()];
                for (int j = 0; j < cityList.size(); j++) {
                    // 遍历省下面的所有市的数据
                    cityNames[j] = cityList.get(j).getName();
                    List<DistrictResult> districtList = cityList.get(j).getDistrictList();
                    String[] distrinctNameArray = new String[districtList.size()];
                    DistrictResult[] distrinctArray = new DistrictResult[districtList.size()];
                    for (int k = 0; k < districtList.size(); k++) {
                        // 遍历市下面所有区/县的数据
                        DistrictResult districtResult = new DistrictResult(districtList.get(k).getName(), districtList.get(k).getZipcode());
                        // 区/县对于的邮编,保存到mZipcodeDatasMap
                        mZipcodeDatasMap.put(districtList.get(k).getName(), districtList.get(k).getZipcode());
                        distrinctArray[k] = districtResult;
                        distrinctNameArray[k] = districtResult.getName();
                    }
                    // 市-区/县的数据,保存到mDistrictDatasMap
                    mDistrictDatasMap.put(cityNames[j], distrinctNameArray);
                }
                // 省-市的数据,保存到mCitisDatasMap
                mCitisDatasMap.put(provinceList.get(i).getName(), cityNames);
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : InputStream(java.io.InputStream) ProvinceResult(com.wheelview.result.ProvinceResult) SAXParser(javax.xml.parsers.SAXParser) DistrictResult(com.wheelview.result.DistrictResult) SAXParserFactory(javax.xml.parsers.SAXParserFactory) CityResult(com.wheelview.result.CityResult)

Example 2 with CityResult

use of com.wheelview.result.CityResult in project AndroidDevelop by 7449.

the class XmlParserHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch(qName) {
        case PROVINCE:
            provinceResult = new ProvinceResult();
            provinceResult.setName(attributes.getValue(0));
            provinceResult.setCityList(new ArrayList<CityResult>());
            break;
        case CITY:
            cityResult = new CityResult();
            cityResult.setName(attributes.getValue(0));
            cityResult.setDistrictList(new ArrayList<DistrictResult>());
            break;
        case DISTRICT:
            districtResult = new DistrictResult();
            districtResult.setName(attributes.getValue(0));
            districtResult.setZipcode(attributes.getValue(1));
            break;
    }
}
Also used : ProvinceResult(com.wheelview.result.ProvinceResult) DistrictResult(com.wheelview.result.DistrictResult) CityResult(com.wheelview.result.CityResult)

Aggregations

CityResult (com.wheelview.result.CityResult)2 DistrictResult (com.wheelview.result.DistrictResult)2 ProvinceResult (com.wheelview.result.ProvinceResult)2 InputStream (java.io.InputStream)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1