【问题标题】:Use Preferences to get SharedPreferences使用 Preferences 获取 SharedPreferences
【发布时间】:2012-02-25 05:22:07
【问题描述】:

我一直在使用共享首选项来存储一些用户值.... 但是当偏好的数量开始增加时。所以我决定使用 PreferenceActivity。

我的问题是我希望我的 prefeneceActivity 使用我之前的共享首选项。 已经完成了共享 prefeneceActivity 的代码,但无法获得使用 sharedpreferences 的选项。

【问题讨论】:

  • 我还是新手,但你不能做一个一次性的活动,将 SharedPreferences 转移到 PreferenceActivity 吗?

标签: android preferences sharedpreferences


【解决方案1】:

使用

SharedPreferences pref= Context.getSharedPreferences("SomePreferences", Context.MODE_PRIVATE);

获取 SharedPreferences,以及

pref.getString(), pref.getInt()..../

从偏好中获取价值。

并将这些值加载到 PreferenceActivity 的组件中。

【讨论】:

  • 谢谢!!! thr 是我的 Eclipse 的问题 ws 给了我错误 bt restrd it n it gt fix ...
【解决方案2】:

代码应该很简单。

SharedPreferences sharedprefs = Context.getSharedPreferences(oldsharedprefs, Context.MODE_PRIVATE);

【讨论】:

    猜你喜欢
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2018-11-01
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多