首页编程preferencecategory 如何设置默认值为 SwitchPreference 的 android 吗

preferencecategory 如何设置默认值为 SwitchPreference 的 android 吗

编程之家2023-11-05218次浏览

你是否曾想过,preferencecategory和如何设置默认值为 SwitchPreference 的 android 吗之间是否存在联系?在本文中,小编将为您探索它们之间的关系,带您领略新的视角和见解。

preferencecategory 如何设置默认值为 SwitchPreference 的 android 吗

employment sponsorship

Employment来自于 employ,ment是它的后缀,只修改词性

意思是指雇佣,或者就业。

sponsorship来自于 sponsor, ship是名词后缀。有几个意思:1.保证人

2.发起人 3.赞助商

application是指申请

你可能是去上学吧。

preferencecategory 如何设置默认值为 SwitchPreference 的 android 吗

一些外国学校会帮助学生有业余工作,

可能问的就是这个!

问你是否需要就业帮助,就是说学校为你提供校内的工作。

如何设置默认值为 SwitchPreference 的 android 吗

没有人用 SwitchPreference类从 android,知道如何去设置的默认值吗?我有以编程方式实现它:

SwitchPreference switch= new SwitchPreference(this);

switch.setKey("preference_my_key");

preferencecategory 如何设置默认值为 SwitchPreference 的 android 吗

switch.setTitle(R.string.preference_title_my_title);

switch.setSummary(R.string.preference_summary_my_summary);

Boolean isChecked= Manager.myMethodIsChecked(MyActivity.this);

switch.setChecked( isChecked);

switch.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){

@Override

public boolean onPreferenceChange(Preference preference, Object newValue){

try{

boolean selected= Boolean.parseBoolean(newValue.toString());

if(!selected){

//do something

}

} catch(Throwable e){

e.printStackTrace();

}

return true;

}

});

category.addPreference(switch);

首选项将所有值入都保存其 xml文件: app_package_name_preferences.xml。

第一次 time的应用程序加载时, switch有"虚假"的默认值。

但我有时需要使默认值"true"。

我试过几种方法,但没有什么工作。

switch.setChecked( true);

switch.setDefaultValue(true);

请帮助我,如果有人知道如何设置此默认值。感谢你在前进 Lidia

解决方法 1:

我为我的问题找到解决办法并将发布它的情况下有人有同样的问题。

正如我告诉,我以编程方式编写首选项

PreferenceScreen root= getPreferenceManager().createPreferenceScreen(this);

PreferenceCategory catView= new PreferenceCategory(this);

catView.setTitle(R.string.preference_category_view);

root.addPreference(catView);

final SwitchPreference switchSplash= new SwitchPreference(this);

switchSplash.setKey(PreferenceKeys.SPLASH);

//-----the above code----

switchSplash.setChecked(false);// LINE 1

catView.addPreference(switchSplash);// LINE 2

在 debug我发现真正的价值设置在行 1,但当我将switchSplash添加到catView, switchSplash的值重置为false,因为catView设置的值从 prefereces xml。

这就是为什么我改变成所需的所有值xml

SharedPreferences.Editor editor= root.getPreferenceManager().getSharedPreferences().edit();

editor.putBoolean(PreferenceKeys.SPLASH, true);

editor.commit();

这是它。

文章到此结束,希望我们对于preferencecategory和如何设置默认值为 SwitchPreference 的 android 吗的问题能够给您带来一些启发和解决方案。如果您需要更多信息或者有其他问题,请随时联系我们。

网络营销品牌?网络营销10大平台个人主页制作?如何制作个人主页