Exemplo n.º 1
0
 /**
  * 保存城市信息
  *
  * @param city
  */
 public void saveCity(City city) {
   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);
 }
Exemplo n.º 2
0
 /**
  * 读取一个省份下的所有城市
  *
  * @param provinceId
  * @return
  */
 public List<City> loadCities(int provinceId) {
   List<City> list = new ArrayList<>();
   String id = String.valueOf(provinceId);
   Cursor c = db.query("City", null, "province_id=?", new String[] {id}, null, null, null);
   if (c != null) {
     while (c.moveToNext()) {
       City city = new City();
       city.setId(c.getInt(c.getColumnIndex("_id")));
       city.setCityCode(c.getString(c.getColumnIndex("city_code")));
       city.setCityName(c.getString(c.getColumnIndex("city_name")));
       city.setProvinceId(provinceId);
       list.add(city);
     }
   }
   c.close();
   return list;
 }