/** 从数据库读取全国所有的省份信息。 */ public List<Province> loadProvinces() { List<Province> list = new ArrayList<Province>(); Cursor cursor = db.query("Province", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { Province province = new Province(); province.setId(cursor.getInt(cursor.getColumnIndex("id"))); province.setProvinceName(cursor.getString(cursor.getColumnIndex("province_name"))); province.setProvinceCode(cursor.getString(cursor.getColumnIndex("province_code"))); list.add(province); } while (cursor.moveToNext()); } return list; }
/* * 解析和处理服务器返回的省级数据 * */ public static synchronized boolean handleProvincesResponse( CoolWeatherDB coolWeatherDB, String response) { if (!TextUtils.isEmpty(response)) { String[] allProvinces = response.split(","); if (allProvinces != null && allProvinces.length > 0) { for (String p : allProvinces) { String[] array = p.split("\\|"); Province province = new Province(); province.setProvinceCode(array[0]); province.setProvinceName(array[1]); coolWeatherDB.saveProvince(province); } return true; } } return false; }