Comment utiliser un contrat de classe dans android?

Je suis un peu confus parce que je ne sais pas comment je dois interpréter le tutoriel ici: http://developer.android.com/training/basics/data-storage/databases.html#DbHelper

Mon code jusqu'à ce que ressemble maintenant à ceci:

public final class DatabaseContract {
//To prevent someone from accidentally instantiating the contract class,
//give it an empty constructor.
public DatabaseContract() {}
public static abstract class Table1 implements BaseColumns {
public static final String TABLE_NAME       = "nameOfTable";
public static final String COLUMN_NAME_COL1 = "column1";
public static final String COLUMN_NAME_COL2 = "column2";
public static final String COLUMN_NAME_COL3 = "column3";
}
public class DatabaseHelper extends SQLiteOpenHelper {
//If you change the database schema, you must increment the database version.
public static final  int    DATABASE_VERSION   = 1;
public static final  String DATABASE_NAME      = "database.db";
private static final String TEXT_TYPE          = " TEXT";
private static final String COMMA_SEP          = ",";
private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " +
Table1.TABLE_NAME + " (" +
Table1._ID + " INTEGER PRIMARY KEY," +
Table1.COLUMN_NAME_COL1 + TEXT_TYPE + COMMA_SEP +
Table1.COLUMN_NAME_COL2 + TEXT_TYPE + COMMA_SEP +
Table1.COLUMN_NAME_COL3 + TEXT_TYPE + COMMA_SEP + " )";
private static final String SQL_DELETE_ALL_ENTRIES = "DROP TABLE IF EXISTS " + Table1.TABLE_NAME;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
//Method is called during creation of the database
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
//Method is called during an upgrade of the database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DatabaseHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
db.execSQL(SQL_DELETE_ALL_ENTRIES);
onCreate(db);
}
}
}

Je n'ai interprété à droite ou à avoir les 6 premières variables dans la classe Helper être à l'extérieur dans la classe de Contrat?
Ou devrait la Classe Helper ne pas être un intérieur de classe de la classe de contrat?

Espère que vous pourrez m'aider

  • La classe helper n'est pas une partie de businessobjects...
  • donc je doit faire une propre Fichier de la classe Helper?
InformationsquelleAutor maysi | 2013-07-03