Creating and Editing Tasks with SQLite

The first thing you need to do is create a task. To do that, you need to insert a record. After that, you need to list the task(s) on the ReminderListActivity, which in turn allows you to tap a task to edit it, or long-press a task to delete it. These user interactions describe the create, read, update, and delete operations for your Task Reminder application. The next few sections show you how to add this functionality.

Inserting your first task entry

Inserting tasks into the SQLite database is a fairly easy process after you get the hang of it. In general terms, you simply follow these steps:

  1. Set up the required local variables.
  2. Build the Save button click listener.
  3. Retrieve values from EditText views.
  4. Interact with the RemindersDbAdapter class.
  5. Open and close the database.

By learning how to insert your first task, you should get a good enough grasp on the SQLiteDatabase class interaction to perform the other necessary tasks. Therefore, in this section I introduce you to the entire implementation of RemindersDbAdapter, which outlines all the CRUD operations. Afterwards, I describe the CRUD tasks in greater detail.

Saving values from the screen to the database

When the user creates a task, it takes place in the ReminderEditActivity. To create the task, you need to create a class-level RemindersDbAdapter variable that is instantiated in the onCreate() method. After it is instantiated, you open the database with a call to the RemindersDbAdapter ...

Get Android™ Tablet Application Development For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.