public void saveProvince(Province province) { if (province != null) { ContentValues values = new ContentValues(); values.put("province_name", province.getProvinceName()); values.put("province_code", province.getProvinceCode()); db.insert("Province", null, values); } }
public List<Province> loadProvinces() { List<Province> list = new ArrayList<Province>(); Cursor cursor = db.query("Province", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { Province province = new Province(); province.setId(cursor.getInt(cursor.getColumnIndex("id"))); province.setProvinceName(cursor.getString(cursor.getColumnIndex("province_name"))); province.setProvinceCode(cursor.getString(cursor.getColumnIndex("province_code"))); list.add(province); } while (cursor.moveToNext()); } return list; }
private void queryCity() { cityList = db.getCities(selectedProvince.getId()); if (cityList.size() > 0) { dataList.clear(); for (City c : cityList) { dataList.add(c.getCityName()); } adapter.notifyDataSetChanged(); listview.setSelection(0); title.setText(selectedProvince.getProvinceName()); currentLevel = LEVEL_CITY; } else { queryServer(selectedProvince.getProvinceCode(), "city"); } }
private void queryProvince() { provinceList = db.getProvinces(); if (provinceList.size() > 0) { dataList.clear(); for (Province p : provinceList) { dataList.add(p.getProvinceName()); } adapter.notifyDataSetChanged(); listview.setSelection(0); title.setText("中国"); currentLevel = LEVEL_PROVINCE; } else { queryServer(null, "province"); } }
/** 查询选中省内所有的市,优先从数据库查询,如果没有查询到再去服务器上查询。 */ private void queryCities() { cityList = coolWeatherDB.loadCities(selectedProvince.getProvinceName()); 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.getCity(), "city"); } }
private void queryProvinces() { provinceList = coolWeatherDB.loadProvinces(); if (provinceList.size() > 0) { dataList.clear(); for (Province province : provinceList) { dataList.add(province.getProvinceName()); } adapter.notifyDataSetChanged(); listView.setSelection(0); titleText.setText("中国"); currentLevel = LEVEL_PROVINCE; } else { queryFromServer(null, "province"); } }
public static synchronized boolean handleProvincesResponse( CoolWeatherDB coolWeatherDB, String response) { if (!TextUtils.isEmpty(response)) { String[] allProvinces = response.split(","); if (allProvinces != null && allProvinces.length > 0) { for (String p : allProvinces) { String[] array = p.split("\\|"); Province province = new Province(); province.setProvinceCode(array[0]); province.setProvinceName(array[1]); coolWeatherDB.saveProvince(province); } return true; } } return false; }