public List<County> loadCounties(int cityId) { List<County> list = new ArrayList<County>(); 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"))); list.add(county); } while (cursor.moveToNext()); } if (cursor != null) { cursor.close(); } return list; }