Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DbHelper extends SQLiteOpenHelper implements IDbHelper {
- ****
- //нужно добавить реализацию методов описанных в интерфейсе
- }
- public interface IDbHelper {
- void saveFavoriteRecipeId(int id, Context context);
- void deleteFavoriteRecipeId(int id);
- boolean recipeIsFavorite(int id);
- }
- /**
- * Singleton that controls access to the SQLiteDatabase instance
- * for this application.
- */
- public class DatabaseManager {
- private static DatabaseManager sInstance;
- public static synchronized DatabaseManager getInstance(Context context) {
- if (sInstance == null) {
- sInstance = new DatabaseManager(context.getApplicationContext());
- }
- return sInstance;
- }
- private DbHelper dbHelper;
- private DatabaseManager(Context context) {
- DbHelper = new DbHelper (context);
- }
- public Cursor queryAllItems(String sortOrder) {
- //TODO: Implement the query
- return null;
- }
- public Cursor queryItemById(int id) {
- //TODO: Implement the query
- return null;
- }
- }
- //получить DAO для работы с БД
- RuntimeExceptionDao<MyData, Integer> myDao = getHelper().getMyDataDao();
- //создать объект
- MyData myData = new MyData();
- //сохранить в БД
- myDao.create(myData);
- //получить список объектов из БД
- List<MyData> myDatas=myDao.queryForAll();
- //перебираем объекты
- for(MyData myData:myDatas) {
- //blah-blah
- }
Add Comment
Please, Sign In to add comment