/** 查询选中省份内所有的市,优先从数据库中查询,如果没有再到服务器上查询 */
 private void queryCites() {
   cityList = terrificWeatherDB.loadCities(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 = LEVEN_CITY;
   } else {
     queryFromServer(selectedProvince.getProvinceCode(), "city");
   }
 }
 /** 查询选中市内所有的县,优先从数据库中查询,如果没有查询到再去服务器上查询 */
 private void queryCounties() {
   countyList = terrificWeatherDB.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");
   }
 }
 /** 查询全国所有的省,优先从数据库查询,如果没有查询到再去服务器上查询 */
 private void queryProvinces() {
   provinceList = terrificWeatherDB.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");
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    isFromWeatherActivity = getIntent().getBooleanExtra("from_weather_activity", false);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("city_selected", false) && !isFromWeatherActivity) {
      Intent intent = new Intent(this, WeatherActivity.class);
      startActivity(intent);
      finish();
      return;
    }
    setContentView(R.layout.choose_area);

    listView = (ListView) findViewById(R.id.list_view);
    titleText = (TextView) findViewById(R.id.title_text);
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dataList);
    listView.setAdapter(adapter);
    terrificWeatherDB = TerrificWeatherDB.getInstance(this);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (currentLevel == LEVEL_PROVINCE) {
              selectedProvince = provinceList.get(position);
              queryCites();
            } else if (currentLevel == LEVEN_CITY) {
              selectedCity = cityList.get(position);
              queryCounties();
            } else if (currentLevel == LEVEL_COUNTY) {
              LogUtil.d("X_Cat", "ChooseAreaActivity-100 onCreate()");
              String countyCode = countyList.get(position).getCountyCode();
              Intent intent = new Intent(ChooseAreaActivity.this, WeatherActivity.class);
              intent.putExtra("county_code", countyCode);
              startActivity(intent);
              finish();
            }
          }
        });
    queryProvinces(); // 加载省级数据
  }