public List<County> loadCounties(int cityId) { List<County> list = new ArrayList<County>(); Cursor cursor = db.query( "County", null, "city_id=?", new String[] {String.valueOf(cityId)}, null, null, null); if (cursor.moveToFirst()) { do { County county = new County(); county.setId(cursor.getInt(cursor.getColumnIndex("id"))); county.setCountyName(cursor.getString(cursor.getColumnIndex("county_name"))); county.setCountyCode(cursor.getString(cursor.getColumnIndex("county_code"))); county.setCityId(cursor.getInt(cursor.getColumnIndex("county_id"))); list.add(county); } while (cursor.moveToNext()); } return list; }
/* * 解析和返回处理服务器返回的县级数据 * */ public static boolean handleCountiesResponse( CoolWeatherDB coolWeatherDB, String response, int cityId) { if (!TextUtils.isEmpty(response)) { String[] allCounties = response.split(","); if (allCounties != null && allCounties.length > 0) { for (String c : allCounties) { String[] array = c.split("\\|"); County county = new County(); county.setCountyCode(array[0]); county.setCountyName(array[1]); county.setCityId(cityId); // 将解析出来的数据存储到County表 coolWeatherDB.saveCounty(county); } return true; } } return false; }