@Overridepublic List<Location> getLocations() { List<Location> list = new ArrayList<>(); Cursor cursor = null; sqLiteDatabase = dbsqLiteOpenHelper.getReadableDatabase(); String sql = "select loca_id, loca_name from location where loca_id not null"; try { cursor = sqLiteDatabase.rawQuery(sql, null); cursor.moveToFirst(); int i = 0; if (cursor.getCount() > 0) { for (i = 0; i < cursor.getCount(); i++) { list.add(new Location(cursor.getString(0), cursor.getString(1))); } } } catch (Exception e) { e.printStackTrace(); Log.e("", e.getMessage()); } finally { if (cursor != null) cursor.close(); } return list; }이런 메소드를 짜 놓으면 0만 들어간다.
이유는 커서도 증가를 시켜야 하는 걸 내가 몰랐기 때문이지.
@Overridepublic List<Location> getLocations() { List<Location> list = new ArrayList<>(); Cursor cursor = null; sqLiteDatabase = dbsqLiteOpenHelper.getReadableDatabase(); String sql = "select loca_id, loca_name from location where loca_id not null"; try { cursor = sqLiteDatabase.rawQuery(sql, null); cursor.moveToFirst(); int i = 0; if (cursor.getCount() > 0) { for (i = 0; i < cursor.getCount(); i++) { list.add(new Location(cursor.getString(0), cursor.getString(1))); cursor.moveToNext(); } } } catch (Exception e) { e.printStackTrace(); Log.e("", e.getMessage()); } finally { if (cursor != null) cursor.close(); } return list; }
이러고 나서 로그 찍어 보면 잘 돌아감.
안드로이드는 이상한 게 많구나.
댓글
댓글 쓰기