Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Contact> getAllContacts() {
- List<Contact> contactList = new ArrayList<Contact>();
- // Select All Query
- String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.rawQuery(selectQuery, null);
- // looping through all rows and adding to list
- if (cursor.moveToFirst()) {
- do {
- Contact contact = new Contact();
- contact.setID(Integer.parseInt(cursor.getString(0)));
- contact.setName(cursor.getString(1));
- contact.setAddress(cursor.getString(2));
- contactList.add(contact);
- } while (cursor.moveToNext());
- }
- // return contact list
- return contactList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement