Kostya, Googling for "android preference subclassing" didn't quite do it. Can you point me in the right direction? What is the format of the XML entry so that it know how to find my subclass? Does the subclass have any requirements if all it will do is override addPreference? Where can I find the info on all this in the developer documentation?
...Jake >>>>> "Jake" == Jake Colman <[email protected]> writes: Jake> Now to Google and figure out how to use my own subclass in an Jake> XML preferences file! Jake> Thanks! Jake> ...Jake >>>>> "KV" == Kostya Vasilyev <[email protected]> writes: KV> Jake, KV> My turn to think I'm missing something. KV> I imagine you have a subclass of PreferenceActivity, with KV> onCreate calling addPreferencesFromResource(R.xml.<some xml id KV> here>). KV> In that XML file, you have your preference item definitions. KV> You can use your own {sub}classes in that XML file, just like KV> with layouts and views (e.g. for a list-of-options type KV> preference, I got sick of having to convert between integers and KV> strings at some point, which is necessary if you use KV> ListPreference, and wrote my own class that uses a list of KV> integers). KV> Now as it turns out, PreferenceScreen is "final" (what the?) so KV> you can't subclass that, but PreferenceCategory is not final, so KV> it can be subclassed and specified in the XML. KV> -- Kostya KV> 2011/5/26 Jake Colman <[email protected]> >>> >>> 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 >>> 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 KV> [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> -- Jake> Jake Colman -- Android Tinkerer Jake> -- Jake> You received this message because you are subscribed to the Google Jake> Groups "Android Developers" group. Jake> To post to this group, send email to [email protected] Jake> To unsubscribe from this group, send email to Jake> [email protected] Jake> For more options, visit this group at Jake> 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

