Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Category is an POJO with id and name properties.
- // DBHelper.TABLE_CATEGORY is name of category table.
- // DBHelper.KEY_ID is column id of category table.
- // DBHelper.KEY_NAME is column name of category table.
- // Database fields
- private String[] allColumns = { DBHelper.KEY_ID, DBHelper.KEY_NAME };
- public ArrayList<Category> getAllCategory() {
- ArrayList<Category> categories = new ArrayList<String>();
- Cursor cursor = database.query(DBHelper.TABLE_CATEGORY, allColumns,
- null, null, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- while (!cursor.isAfterLast()) {
- Category category = new Category();
- category.setId(c.getInt(c.getColumnIndex(DBHelper.KEY_ID)));
- category.setName(c.getString(c.getColumnIndex(DBHelper.KEY_NAME)));
- categories.add(category);
- cursor.moveToNext();
- }
- cursor.close();
- }
- return categories;
- }
Add Comment
Please, Sign In to add comment