public List<User> getAllUser() { List<User> userList = new ArrayList<User>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_USER; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { User user = new User(); user.setPassword(cursor.getString(0)); user.setToken(cursor.getString(1)); user.setUserId(Integer.parseInt(cursor.getString(2))); user.setUsername(cursor.getString(3)); user.setDateCreated(cursor.getString(4)); user.setFirstName(cursor.getString(5)); user.setLastName(cursor.getString(6)); user.setGender(cursor.getString(7)); // Adding user to list userList.add(user); } while (cursor.moveToNext()); } // return user list return userList; }
// Getting All Users public List<User> getAllUsers(int page) { List<User> userList = new ArrayList<User>(); // Select All Query // String selectQuery = "SELECT * FROM " + TABLE_USER; SQLiteDatabase db = this.getWritableDatabase(); // Cursor cursor = db.rawQuery(selectQuery, null); Cursor cursor = db.query( TABLE_USER, null, null, null, null, null, null, ((page - 1) * PAGE_SIZE) + ", " + PAGE_SIZE); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { User user = new User(); user.setUserId(Integer.parseInt(cursor.getString(0))); user.setUsername(cursor.getString(1)); user.setPassword(cursor.getString(2)); user.setToken(cursor.getString(3)); user.setFirstName(cursor.getString(5)); user.setLastName(cursor.getString(6)); user.setGender(cursor.getString(7)); user.setStatus(cursor.getString(8)); // Adding person to list userList.add(user); } while (cursor.moveToNext()); } cursor.close(); // return person list return userList; }