You are asked to design a simple notes list application (i.e Notepad) that lets the user...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 } 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 }
Expert Answer:
Answer rating: 100% (QA)
Answer The code is as follow import androidcontentContentValues import androidcontentContext import androiddatabaseCursor import androiddatabaseSQLExc... View the full answer
Related Book For
Systems Analysis And Design
ISBN: 978-1119496489
7th Edition
Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth
Posted Date:
Students also viewed these programming questions
-
1.5. (a) A 2D transformation is given by (1) a translation of T(2, 3), a scaling of S(1, 2), and a rotation of R), find a combination of these three transformations in one homogeneous matrix. (b) A...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
4. Ethan bought new car worth $60 000. After 5 years, the car was worth $35 429.40. Calculate the depreciation rate of the Ethan's car. [T4] [C2]
-
What are the three workflows in the revised SELECT Perspective (Apperly et al., 2003)?
-
1. What is the 80th percentile of the standard normal distribution? 2. What is the 40th percentile of the standard normal distribution?
-
Cadux Candy Company's income statement for the year ended December 31, 2011, reported interest expense of $2 million and income tax expense of $12 million. Current assets listed in its balance sheet...
-
Which of the following procedures is most telling in addressing the existence assertion for accounts payable? a. Test for unrecorded liabilities. b. Confirm balances with creditors. c. Verify the...
-
Recording Encumbrances. During July 2010, the first month of the 2011 fiscal year, the City of Marion issued the following purchase orders and contracts (see Problem 34): General...
-
In what ways is the "Ohio State" model of leadership different from the "Trait Theory" of leadership? Explain, and be specific. In what ways is the "Ohio State" model of leadership different from the...
-
AnderSet Laboratories produces rough lenses that will ultimately be ground into precision lenses for use in laboratory equipment. The company has developed the following thickness measures, based on...
-
Assume that youre going to the capital city of another country on business two months from now. (You pick the country.) Use a search engine to find out What holidays will be celebrated in that...
-
Before you begin working on a team project, develop a team action plan to establish a framework that will hold your team members accountable for their work. After reading the project assignment sheet...
-
In this exercise, you are going to participate in a networking event, an abbreviated talk and walk. To prepare for the event: Prepare business cards for yourself, using a computer application of...
-
Its often said that theres no I in team because on the best teams, everyone works together for the good of the group. What happens when you encounter a team member who believes that theres a me in...
-
When Amazon brought Kindle to market in 2007, CEO Jeff Bezos sent shareholders a letter telling the story of the creation of the device. Read the letter at...
-
Two carts A and B being hauled by a cable up the incline of a roller coaster. The weight of cart A is 1700 lb and the weight of car B is 1500 lb.he carts start at the bottom of the incline and...
-
Find the numerical value of each expression. (a) sech 0 (b) cosh -1 1
-
Describe the factors that the project manager must evaluate when a project falls behind schedule.
-
What are the six general skills all project team members should have?
-
Create a set of use cases for the process of buying glasses from the viewpoint of the patient, but do not bother to identify the steps within each use case. (Just complete the information at the top...
-
The following data relate to the manufacturing activities of MilTech company during November: 1. Sales $400,000 2. Purchases $60,700 3. Expenses include: Light and power for manufacturing: $2,700 ...
-
Continuing problem 6, CardioMeds cost accountants have identified cost totals for the periods production support activities and other overhead. The table below provides this information, along with...
-
Which are the main cost types in inventory valuation for manufacturing companies? What are the criteria for their classification?
Study smarter with the SolutionInn App