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;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
class RestaurantHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="lunchlist.db";
private static final int SCHEMA_VERSION=1;
public RestaurantHelper(Context context) {
super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
This says that our database name is lunchlist.db, we are using the first version of the schema...and not much else. However, the project should still compile cleanly after adding this class.
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;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
class RestaurantHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME="lunchlist.db";
private static final int SCHEMA_VERSION=1;
public RestaurantHelper(Context context) {
super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
This says that our database name is lunchlist.db, we are using the first version of the schema...and not much else. However, the project should still compile cleanly after adding this class.
No comments:
Post a Comment