Chapter 16. Basic Cursors: Getting Data Out

So how do you connect your app to a SQLite database?

So far you’ve seen how to create a SQLite database using a SQLite helper. The next step is to get your activities to access it. In this chapter, we’ll focus on how you read data from a database. You’ll find out how to use cursors to get data from the database. You’ll see how to navigate cursors, and how to get access to their data. Finally, you’ll discover how to use cursor adapters to bind cursors to list views.

The story so far...

In Chapter 15, you created a SQLite helper for Starbuzz Coffee. The SQLite helper creates a Starbuzz database, adds a DRINK table to it, and populates the table with drinks.

The activities in the Starbuzz app currently get their data from the Java Drink class. We’re going to change the app so the activities get data from the SQLite database instead.

Here’s a reminder of how the app currently works:

  1. TopLevelActivity displays a list of options for Drinks, Food, and Stores.

  2. When the user clicks on the Drinks option, it launches DrinkCategoryActivity.

    This activity displays a list of drinks that it gets from the Java Drink class.

  3. When the user clicks on a drink, its details get displayed in DrinkActivity.

    DrinkActivity gets details of the drink from the Java Drink class.

Get Head First Android Development, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.