use of com.wheelview.result.ProvinceResult 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();
}
}
use of com.wheelview.result.ProvinceResult 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;
}
}
Aggregations