Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public List<Contact> getAllContacts() {
  2. List<Contact> contactList = new ArrayList<Contact>();
  3. // Select All Query
  4. String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
  5.  
  6. SQLiteDatabase db = this.getReadableDatabase();
  7. Cursor cursor = db.rawQuery(selectQuery, null);
  8.  
  9. // looping through all rows and adding to list
  10. if (cursor.moveToFirst()) {
  11. do {
  12. Contact contact = new Contact();
  13. contact.setID(Integer.parseInt(cursor.getString(0)));
  14. contact.setName(cursor.getString(1));
  15. contact.setAddress(cursor.getString(2));
  16.  
  17. contactList.add(contact);
  18. } while (cursor.moveToNext());
  19. }
  20.  
  21. // return contact list
  22. return contactList;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement