Kostya, Maybe I'm missing something obvious here but where do I get an opportunity to provide Android with my extended PreferenceGroup or PreferenceScreen? I need to make sure that my addPreference method called during the processing sequence initiated by addPreferencesFromResource. But how would that code know to use my extended PreferenceScreen so that it uses my overridden addPreference method? Is there a 'set' method somewhere that allows me to specify my extended class?
...Jake >>>>> "KV" == Kostya Vasilyev <[email protected]> writes: KV> Preference.onSetInitialValue is triggered by KV> addPreferencesFromResource, which in turn is called from within KV> your activity's onCreate - not before. KV> However, this happens before your code has a change to call KV> findPreference / setKey. KV> One of the methods that gets called while this is taking place is KV> PreferenceGroup.addPreference. This could be a reasonable place KV> to reset the keys, so it happens before onSetInitialValue. The KV> actual subclasses are PreferenceScreen and PreferenceCategory. KV> You can check for a specifc runtime class by using Java KV> 'instanceof' operator (but this should not be necessary with KV> overiding addPreference). KV> -- Kostya KV> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to [email protected] KV> To unsubscribe from this group, send email to KV> [email protected] KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- 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

