Beispiel #1
0
 public void saveCounty(County county) {
   if (county != null) {
     ContentValues values = new ContentValues();
     values.put("county_name", county.getCountyName());
     values.put("county_code", county.getCountyCode());
     values.put("city_id", county.getCityId());
     db.insert("County", null, values);
   }
 }
Beispiel #2
0
 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("city_id")));
       list.add(county);
     } while (cursor.moveToNext());
   }
   if (cursor != null) {
     cursor.close();
   }
   return list;
 }