예제 #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);
   }
 }
 private void queryCities() {
   cityList = coolWeatherDB.loadCites(selectedProvince.getId());
   if (cityList.size() > 0) {
     dataList.clear();
     for (City city : cityList) {
       dataList.add(city.getCityName());
     }
     adapter.notifyDataSetChanged();
     listView.setSelection(0);
     titleText.setText(selectedProvince.getProvinceName());
     currentLevel = LEVEL_CITY;
   } else {
     queryFromServer(selectedProvince.getProvinceCode(), "city");
   }
 }
예제 #3
0
 public List<City> loadCites(int provinceId) {
   List<City> list = new ArrayList<>();
   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(cursor.getInt(cursor.getColumnIndex("province_id")));
       list.add(city);
     } while (cursor.moveToNext());
   }
   return list;
 }