Preference.onSetInitialValue is triggered by addPreferencesFromResource,
which in turn is called from within your activity's onCreate - not before.

However, this happens before your code has a change to call findPreference /
setKey.

One of the methods that gets called while this is taking place is
PreferenceGroup.addPreference. This could be a reasonable place to reset the
keys, so it happens before onSetInitialValue. The actual subclasses are
PreferenceScreen and PreferenceCategory.

You can check for a specifc runtime class by using Java 'instanceof'
operator (but this should not be necessary with overiding addPreference).

-- Kostya


2011/5/26 Jake Colman <[email protected]>

> >>>>> "S" == String  <[email protected]> writes:
>
>   S> On Thursday, May 26, 2011 2:44:37 AM UTC+1, Jake Colman wrote:
>
>   S> The only issue is when I launch the Preference
>    >> Activity from the widget it does not display the widget-specific
> value
>   >> but displays the preference's default value.
>   >>
>    S> Are you actively setting the value for each of your
>   S> widget-specific preferences, or are you just setting the key and
>   S> hoping they'll pick up the correct (initial) value from the
>   S> SharedPreferences? I think you need to do the former rather than
>   S> the latter.
>
>   S> IOW, my experience is that the initialization of the preferences
>   S> in a PreferenceActivity happens before your onCreate() handler is
>   S> called, so changing preferences' keys there won't affect their
>   S> displayed values. You should just need a simple call to
>   S> setChecked() for each boolean preference to initialize it to the
>   S> appropriate, widget-specific value.
>
> String,
>
> What I am seeing is consistent with what you stated, namely, that by the
> time onCreate is called, the preferences are already initialized so the
> displayed values have already been set.  But why does this only effect
> my CheckBoxPreferences whil my ListPrefeference values are being set
> correctly?
>
> When I call findPreference is there a way for me to determine the
> specific derived Preference class that I acually got?  With C++ I can
> dynamic_cast the base class to find out its actual type.  How does one
> do the same in Java?  If so, then in the method that resets the generic
> preference key to a widget-specific key I can check whether the
> Preference is actually a checkbox and then get and set its actual value.
>
> Hmmmmm.  Maybe I should just write some code to always just drill into
> the SharedPreferences and manually set the value across all types.  As
> long as I can query the Preference object to get its specific type, I
> can generically explicitly set the value for all preferences.
>
> --
> Jake Colman -- Android Tinkerer
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to