我正在嘗試使一個微調器,它將動態加載選項。我希望微調器能夠展示不同的月份,但是如果我有很多這種類型的東西呢?Spinner顯示數據庫的月份
看我的例子:
每次用戶使用該他做一個新的日期,因此有一個月多天,我想只有一個在微調顯示:
的日期看起來像這樣
2013-10-04
2013-10-04
2013-10-02
我想從我的sql數據庫中創建月份。
如何在十月份在我的微調器中創建一個選項?
我希望這聽起來不容易混淆。
感謝您的幫助。
這是我的Sql數據庫。
public class KilometerSQL {
public static final String KEY_ROWID = "date";
public static final String KEY_KILOMETER = "kilometer";
public static final String KEY_LOCATIONS = "locations";
private static final String DATABASE_NAME = "Kilometerdb";
private static final String DATABASE_TABLE = "kilometertable";
private static final int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " TEXT NOT NULL, " +
KEY_KILOMETER + " INTEGER, " +
KEY_LOCATIONS + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public KilometerSQL (Context c){
ourContext = c;
}
public KilometerSQL open(){
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
}
public long createEntry(String date, int kortekm, String locations) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_ROWID, date);
cv.put(KEY_KILOMETER, kortekm);
cv.put(KEY_LOCATIONS, locations);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
// TODO Auto-generated method stub
String [] columns = new String []{ KEY_ROWID, KEY_KILOMETER, KEY_LOCATIONS};
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iDate = c.getColumnIndex(KEY_ROWID);
int iKilometer = c.getColumnIndex(KEY_KILOMETER);
int iLocations = c.getColumnIndex(KEY_LOCATIONS);
for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
result = result + c.getString(iDate) + " " + c.getString(iKilometer) + " " + c.getString(iLocations) + "\n";
}
return result;
}
}
我知道這可能聽起來微不足道,爲什麼你不使用Android的內置'DatePicker'? :http://developer.android.com/guide/topics/ui/controls/pickers.html – Kristopher
嗯..我不認爲我可以使用它.. 因爲當用戶選擇了一個月,他會能夠看到他跑過的所有公里,我希望每次都能顯示出來,他出去跑步。 – Niller
好吧,現在我想我明白你的意思了。請顯示您的數據庫創建語句,讓我知道如何存儲這些日期。 – Kristopher