Android Programming Tutorials

(Romina) #1

TUTORIAL 11


The Restaurant Store


In this tutorial, we will create a database and table for holding our


restaurant data and switch from our ArrayAdapter to a CursorAdapter, to


make use of that database. This will allow our restaurants to persist from


run to run of LunchList.


Step-By-Step Instructions..........................................................................


First, you need to have completed the previous tutorial. If you are


beginning the tutorials here, or if you wish to not use your existing work,


you can download a ZIP file with all of the tutorial results, and you can copy


the 10-Resources edition of LunchList to use as a starting point.


Step #1: Create a Stub SQLiteOpenHelper.........................................


First, we need to be able to define what our database name is, what the


schema is for the table for our restaurants, etc. That is best wrapped up in a


SQLiteOpenHelper implementation.


So, create LunchList/src/apt/tutorial/RestaurantHelper.java, and enter in


the following code:


package apt.tutorial;

import android.content.Context;
import android.database.SQLException;

93
Free download pdf