首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLiteOpenHelper中的getSharedPreferences()

SQLiteOpenHelper中的getSharedPreferences()
EN

Stack Overflow用户
提问于 2016-09-13 21:18:57
回答 1查看 257关注 0票数 0

我有这样一段代码,我将用相同的DueDateTime获取所有可用行

代码语言:javascript
复制
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; }

EN

回答 1

Stack Overflow用户

发布于 2016-09-14 02:32:09

我能做的唯一的解决方案是将getListSched迁移到需要它的活动(仅针对特定活动),然后调用DatabaseSched类(它有SQLiteOpenHelper),这样我就可以使用sharedPreference了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39471156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档