O'Reilly logo

Android™ Tablet Application Development For Dummies® by Donn Felker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required