public class Base extends SQLiteOpenHelper {
public static final String DB_NAME ="db_workout2";//name of base
public static final String DB_TABLE ="dateOfWorkout2";//name of table
public static final int DB_VER =1;
private static Base sInstance;
public static synchronized Base getInstance(Context applicationContext) {
if (sInstance == null) {
sInstance = new Base(applicationContext);
}
return sInstance;
}
private Base(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DB_NAME, null, DB_VER);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(
"create table "+ DB_TABLE +"("
+ "nr integer primary key autoincrement,"
+ "name text,"
+ "s1 integer,"
+ "s2 integer,"
+ "s3 integer,"
+ "s4 integer,"
+ "s5 integer,"
+ "weight integer,"
+"ddate text);"
+"");
}
public void addWorkoutPlan(String i, int q, int w, int e, int r, int t, int wt,String d) {
SQLiteDatabase db = getWritableDatabase();
ContentValues wartosci = new ContentValues();
wartosci.put("name", i);
wartosci.put("s1", q);
wartosci.put("s2", w);
wartosci.put("s3", e);
wartosci.put("s4", r);
wartosci.put("s5",t);
wartosci.put("weight",wt);
wartosci.put("ddate",d);
db.insertOrThrow(DB_TABLE, null, wartosci);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
onCreate(db);
}
public List<String> getDateLabels(){
List<String> labels = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM " + DB_TABLE;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
labels.add(cursor.getString(1));
} while (cursor.moveToNext());
}
// closing connection
cursor.close();
db.close();
// returning lables
return labels;
}
}
[鏈接] https://zapodaj.net/images/b021c721d5efb.jpg 現在看起來這一點。 – Xalion
你正在使用哪個IDE? –
Android Studio 2.1.2 – Xalion