/** 查询选中市内所有的县,优先从数据库查询,如果没有查询到再去服务器上查询。 */
 private void queryCounties() {
   countyList = coolWeatherDB.loadCounties(selectedCity.getId());
   if (countyList.size() > 0) {
     dataList.clear();
     for (County county : countyList) {
       dataList.add(county.getCountyName());
     }
     adapter.notifyDataSetChanged();
     listView.setSelection(0);
     titleText.setText(selectedCity.getCityName());
     currentLevel = LEVEL_COUNTY;
   } else {
     queryFromServer(selectedCity.getCityCode(), "county");
   }
 }
Example #2
0
 /** 解析和处理服务器返回的县级数据 */
 public static synchronized boolean handleCountiesResponse(
     CoolWeatherDB coolWeatherDB, String response, int cityId) {
   if (!TextUtils.isEmpty(response)) {
     String[] allCounties = response.split(",");
     if (allCounties != null && allCounties.length > 0) {
       for (String c : allCounties) {
         String[] array = c.split("\\|");
         County county = new County();
         county.setCountyCode(array[0]);
         county.setCountyName(array[1]);
         county.setCityId(cityId);
         // 将解析出来的数据存储到County表
         coolWeatherDB.saveCounty(county);
       }
       return true;
     }
   }
   return false;
 }