Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    isFromWeatherActivity = getIntent().getBooleanExtra("from_weather_activity", false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Log.i("COME isFromWeatherActivity", isFromWeatherActivity + "");
    Log.i("COME prefs", prefs.getBoolean("city_selected", false) + "");
    if (prefs.getBoolean("city_selected", false) && !isFromWeatherActivity) {
      Log.i("Intent", "here!");
      Intent intent = new Intent(ChooseAreaActivity.this, WeatherActivity.class);

      startActivity(intent);

      finish();
      return;
    }

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    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);
    leWeatherDB = LeWeatherDB.getInstance(this);
    listView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
            if (currentLevel == LEVEL_PROVINCE) {
              if (provinceList.get(index).getChildCount() != 0) {
                selectedProvince = provinceList.get(index);
                queryCities();
              }
            } else if (currentLevel == LEVEL_CITY) {

              String cityName = cityList.get(index).getCityName();
              Intent intent = new Intent(ChooseAreaActivity.this, WeatherActivity.class);
              intent.putExtra("city_name", cityName);

              startActivity(intent);
              finish();
            }
          }
        });
    queryProvinces();
  }
Ejemplo n.º 2
0
 // 查询选中市内所有的县,优先从数据库查询,如果没有查询到再去服务器上查询。
 private void queryCounties() {
   countyList = leWeatherDB.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");
   }
 }
Ejemplo n.º 3
0
 private void queryProvinces() {
   provinceList = leWeatherDB.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");
   }
 }
Ejemplo n.º 4
0
 // 查询选中省内所有的市,优先从数据库查询,如果没有查询到再去服务器上查询。
 private void queryCities() {
   cityList = leWeatherDB.loadCities(selectedProvince.getId());
   // Log.i("queryCities", cityList.size() + "--" +
   // 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");
   }
 }