Esempio n. 1
0
  /**
   * 保存County数据
   *
   * @param county
   */
  public void saveCounty(County county) {
    if (null != county) {
      ContentValues values = new ContentValues();
      values.put("county_name", county.getCountyName());
      values.put("county_code", county.getCountyCode());
      values.put("city_id", county.getCityId());

      db.insert("County", null, values);
    }
  }
Esempio n. 2
0
  /**
   * 加载county数据
   *
   * @param cityId
   * @return
   */
  public List<County> loadCounties(int cityId) {
    List<County> countyList = new ArrayList<>();
    Cursor cursor =
        db.query(
            "County", null, "city_id=?", new String[] {String.valueOf(cityId)}, null, null, null);

    if (cursor.moveToFirst()) {
      do {
        County county = new County();
        county.setId(cursor.getInt(cursor.getColumnIndex("id")));
        county.setCountyName(cursor.getString(cursor.getColumnIndex("county_name")));
        county.setCountyCode(cursor.getString(cursor.getColumnIndex("county_code")));
        county.setCityId(cursor.getInt(cursor.getColumnIndex("city_id")));

        countyList.add(county);
      } while (cursor.moveToNext());
    }

    return countyList;
  }