开发者

How to Initialize Preferences Screen on First Invocation?

I believe I am correctly initializing preferences from XML. My Preferences Screen also works properly and reflects the correct user selected settings.

However, upon first invocation of that Preferences Screen, none of the settings are checked (checkbox) or selected (list). This, of course, confuses the user as it doesn't reflect the current (default/initial) value.

Since all I do to invoke the Preferences Screen is

startActivity(new Intent(this, EditPreferences.class));

And my EditPreferences class only contains:

  @Override
  publi开发者_JS百科c void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.usersettings);
  }

I am not sure where or how to tell it to pre-initialize the visual display with the default setting.

I have this hunch that all I am missing is a single line somewhere, but I don't know where: XML file? override a method in EditPreferences? Other?


Can't you define the default value in the XML itself?

<CheckBoxPreference ...
   android:defaultValue="true" 
   ... />


You can specify a default value on a preference (in your xml layout for example):

<EditTextPreference android:defaultValue="whatever" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜