for 반복문의 코드이다.
if(cursor.moveToFirst()){
for(int i = 0; i < cursor.getCount(); i++ ){
Contact contact = new Contact(cursor.getInt(0), cursor.getString(1), cursor.getString(2));
contactList.add(contact);
cursor.moveToNext();
}
}
while 반복문의 코드이다. do { } while { } 의 모습을 가지고 있다.
if(cursor.moveToFirst()){
do{
Contact contact = new Contact(cursor.getInt(0), cursor.getString(1), cursor.getString(2));
contactList.add(contact);
}while(cursor.moveToNext());
}
커서를 계속 처음으로 가져오는 movetoFirst 와 커서가 다음으로 움직이게 하는 movetoNext 를 사용한 코드이다.
'Android' 카테고리의 다른 글
| Android Studio - RecycleView와 Adapter를 이용하여 리스트를 화면에 표시하는 방법 (0) | 2022.07.14 |
|---|---|
| Android Studio - 빠르게 Linear Layout Resource 파일 만들기 (0) | 2022.07.14 |
| Android Studio - SQLite3 데이터베이스 활용하는 방법 (0) | 2022.07.14 |
| Android Studio - SharedPreferences를 이용한, 데이터의 저장과 불러오기 (0) | 2022.07.13 |
| Android Studio - 액티비티 간의 양방향 데이터 전달방법 (0) | 2022.07.13 |
댓글