我有preferences页面。它有场显示信息屏(如复选框)。
我也有信息网页,其中也应该有复选框再次让我看看'。
正如我已经明白了,我可以通过 preferencesManager.getDefault preferences(上下文)
...
不过,我应该怎么设置preferences价值的信息页面的复选框?
我试图用 context.getShared preferences(preF_NAME,0).edit()
,设定值,但它不与关联preferencesManager的相应值。
我应该怎么办??? F1
解决方案这要看你是否是一组preferences为您的应用程序,或者每个活动一组后。
我用code是这样的:
共享preferences preFS = preferenceManager.getDefaultShared preferences(的getContext());
编辑EDITOR = prefs.edit();
editor.putBoolean(preF_NAME,假);
editor.commit();
和
共享preferences preFS = preferenceManager.getDefaultShared preferences(的getContext());
如果(prefs.getBoolean(preF_NAME,真)){
// 等等
}
I have preferences page. It has field 'Show info screen' (as checkbox).
I have also info page which also should have checkbox 'Show me again'.
As I've understand, I can get value from preferences page via PreferencesManager.getDefaultPreferences(context)
...
But how I should set preferences value for the checkbox on info page?
I tried to use context.getSharedPreferences(PREF_NAME, 0).edit()
, to set value but it doesn't correlate with PreferencesManager's corresponding value.
What should I do??? F1
解决方案It depends on whether you are after one set of preferences for your application, or one set per activity.
I've used code like this:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
Editor editor = prefs.edit();
editor.putBoolean(PREF_NAME, false);
editor.commit();
and
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (prefs.getBoolean(PREF_NAME, true)) {
// etc
}
相关推荐
最新文章