我正在尝试制作一个可以动态加载选项的微调器。我希望微调器显示不同的月份,但如果我有很多这样的月份怎么办?
看我的例子:
每次用户使用它时,他都会创建一个新日期,因此一个月中有很多天,我希望在微调器中只显示一个:
日期看起来像这样
2013-10-04
2013-10-04
2013-10-02
我想从我的 sql 数据库创建月份。
如何在 10 月的微调器中选择一个选项?
我希望这听起来不会让人困惑。
谢谢你的帮助。
这是我的 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;
}
}