我有这样一段代码,我将用相同的DueDateTime获取所有可用行
public List<DatabaseSource> getListSched() {
text = sharedPreference.getValue2(context);
String shareFact = text.toString();
List<DatabaseSource> schedList= new ArrayList<DatabaseSource>();
// Select All Query
String selectQuery = "SELECT * FROM schedTBL WHERE DueDateTime like " + shareFact;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
DatabaseSource sched= new DatabaseSource();
sched.setId(Integer.parseInt(cursor.getString(0)));
sched.setSubject(cursor.getString(1));
sched.setDescription(cursor.getString(2));
sched.setDueDateTime(cursor.getString(3));
// Adding sched to list
contactList.add(sched);
} while (cursor.moveToNext());
}
// return schedlist
return schedList;
}我做得对吗??,似乎我不能在其中使用共享首选项,我有SharedPreferencesUID类,我存储下面的代码来获得我想要的值
public String getValue2(Context context) { SharedPreferences settings; String text; //settings = PreferenceManager.getDefaultSharedPreferences(context); settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); text = settings.getString("dateselected", null); return text; }
发布于 2016-09-14 02:32:09
我能做的唯一的解决方案是将getListSched迁移到需要它的活动(仅针对特定活动),然后调用DatabaseSched类(它有SQLiteOpenHelper),这样我就可以使用sharedPreference了。
https://stackoverflow.com/questions/39471156
复制相似问题