/** * 读取省份信息 * * @return */ public List<Province> loadProvinces() { List<Province> list = new ArrayList<>(); Cursor cursor = db.query("Province", null, null, null, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { 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); } } cursor.close(); return list; }
/** * 保存省份信息 * * @param province */ public void saveProvince(Province province) { ContentValues values = new ContentValues(); values.put("province_name", province.getProvinceName()); values.put("province_code", province.getProvinceCode()); db.insert("Province", null, values); }