/** * 保存县级信息 * * @param country */ public void saveCountry(Country country) { ContentValues values = new ContentValues(); values.put("country_name", country.getCountryName()); values.put("country_code", country.getCountryCode()); values.put("city_id", country.getCityId()); db.insert("Country", null, values); }
/** * 读取一个城市所有的县的信息 * * @param cityId * @return */ public List<Country> loadCountries(int cityId) { List<Country> list = new ArrayList<>(); Cursor cursor = db.query( "Country", null, "city_id=?", new String[] {String.valueOf(cityId)}, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { Country country = new Country(); country.setId(cursor.getInt(cursor.getColumnIndex("_id"))); country.setCountryCode(cursor.getString(cursor.getColumnIndex("country_code"))); country.setCountryName(cursor.getString(cursor.getColumnIndex("country_name"))); country.setCityId(cityId); list.add(country); } } cursor.close(); return list; }