Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

You are asked to design a simple notes list application (i.e Notepad) that lets the user add new notes. You will have to use

You are asked to design a simple notes list application (i.e Notepad) that lets the user add new notes. You public class NotesDbAdapter { public static final String COLUMN_TITLE= A. Complete the class below by creating a table that contains one column for each attribute. private static C. implement fetchAllNotes() to issue a query from the database to return all the notes in the database.

You are asked to design a simple notes list application (i.e Notepad) that lets the user add new notes. You will have to use SQLite database to store the notes. You will have to implement the NotesDbAdapter class, meant to encapsulate data access to a SQLite database that will hold our notes data and allow us to update it. The database will have the name data, and have a single table called notes, which in turn has three fields: _id, title and body. The _id usually has to be specified when querying or updating the database (in the column projections and so on). The other two fields are simple text fields that will store data. The NotesDbAdapter class, will have the following methods to implement various DB operations: The open() method calls up an instance of DatabaseHelper, which is the local implementation of the SQLiteOpenHelper class and handles creating/opening a database. close() just closes the database, releasing resources related to the connection. createNote() takes strings for the title and body of a new note, then creates that note in the database. Assuming the new note is created successfully, the method also returns the row_id value for the newly created note. deleteNote() takes a rowld for a particular note, and deletes that note from the database. fetchAllNotes() issues a query to return a Cursor over all notes in the database. updateNote() takes a rowld, title and body, and updates the note of the given rowld. public class NotesDbAdapter { public static final String COLUMN_TITLE = "title"; public static final String COLUMN_BODY = "body"; public static final String COLUMN_ID = "_id"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; private static final String DATABASE_NAME = "data"; private static final String TABLE_NAME = "notes"; private static final int DATABASE_VERSION = 1; private final context mContext; private static class DatabaseHelper extends SQLiteOpenHelper {...} public NotesDbAdapter (Context ctx) { this.mCtx = ctx; } public NotesDbAdapter open() throws SQLException {...} public void close() {} public long createNote (String title, String body) {...} public boolean deleteNote (long rowId) {...} public Cursor fetchAllNotes () {-} public boolean updateNote (long rowId, String title, String body) {..... } A. Complete the class below by creating a table that contains one column for each attribute. private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper (Context context) { super (context, DATABASE_NAME, null, DATABASE_VERSION); } } @Override public void onCreate(SQLiteDatabase db) { //1. ADD YOUR CODE HERE } @Override public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) { //2. ADD YOUR CODE HERE } public NotesDbAdapter open() throws SQLException { mDbHelper = new DatabaseHelper (mCtx); mDb = mDbHelper.getwritableDatabase(); return this; } public void close() { mDbHelper.close(); } } B. Implement methods to create/delete/update notes from the database. public long createNote (String title, String body) { //3. ADD YOUR CODE HERE } public boolean deleteNote (long rowId) { //4. ADD YOUR CODE HERE } public boolean updateNote (long rowId, String title, String body) { //5. ADD YOUR CODE HERE C. implement fetchAllNotes() to issue a query from the database to return all the notes in the database. public Cursor fetchAllNote() { //6. ADD YOUR CODE HERE }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Answer The code is as follow import androidcontentContentValues import androidcontentContext import androiddatabaseCursor import androiddatabaseSQLExc... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Design

Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth

7th Edition

1119496489, 978-1119496489

More Books

Students explore these related Programming questions

Question

Is tire service system of WestJet JIT/lean?

Answered: 3 weeks ago