Пример #1
0
 public void saveCity(City city) {
   if (city != null) {
     ContentValues values = new ContentValues();
     values.put("city_name", city.getCityName());
     values.put("city_code", city.getCityCode());
     values.put("province_id", city.getProvinceId());
     db.insert("city", null, values);
   }
 }
Пример #2
0
 public List<City> loadCity(int provinceId) {
   List<City> list = new ArrayList<City>();
   Cursor cursor =
       db.query(
           "city",
           null,
           "province_id = ?",
           new String[] {String.valueOf(provinceId)},
           null,
           null,
           null);
   if (cursor.moveToFirst()) {
     do {
       City city = new City();
       city.setId(cursor.getInt(cursor.getColumnIndex("id")));
       city.setCityName(cursor.getString(cursor.getColumnIndex("city_name")));
       city.setCityCode(cursor.getString(cursor.getColumnIndex("city_code")));
       city.setProvinceId(provinceId);
       list.add(city);
     } while (cursor.moveToNext());
   }
   cursor.close();
   return list;
 }