public long createFav(Favorite fav) { ContentValues cv = new ContentValues(); cv.put(FAV_ID, fav.getFav()); cv.put(FAV_TITLE, fav.getFavTitle()); cv.put(FAV_IMAGE, fav.getFavImage()); cv.put(FAV_DESC, fav.getFavDesc()); cv.put(FAV_TIME, fav.getDate()); cv.put(KEY_CREATED_AT, getDateTime()); long favorite = sqLiteDatabase.insert(TABLE_FAVORITE, null, cv); return favorite; }
public List<Favorite> getAllFavorite() { List<Favorite> favoriteItems = new ArrayList<Favorite>(); String selectQuery = "SELECT * FROM " + TABLE_FAVORITE; Cursor c = sqLiteDatabase.rawQuery(selectQuery, null); // looping through all rows and adding to list if (c.moveToFirst()) { do { Log.e(LOG, selectQuery); Favorite fav = new Favorite(); fav.setFav(c.getInt(1)); fav.setFavDesc(c.getString(c.getColumnIndex(FAV_DESC))); fav.setDate(c.getString(c.getColumnIndex(FAV_TIME))); fav.setImage(c.getString(c.getColumnIndex(FAV_IMAGE))); fav.setFavTitle(c.getString(c.getColumnIndex(FAV_TITLE))); // adding to tags list favoriteItems.add(fav); } while (c.moveToNext()); } return favoriteItems; }