Preferences are inflated with a Context, which in this case is your
PreferenceActivity subclass.

I'd make two classes, WidgetOptionsActivity and
WidgetOptionsPreferenceCategory, with the expectation that the latter is
always used within the former (like maps API and MapActivity).

The widget id is passed to the activity as an intent extra, so just get it
from there and make available as a method / field before you call
addPreferencesFromResource().

Then you could derive YourProjectNameWidgetOptionsActivity from
WidgetOptionsActivity.

-- Kostya

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

>
> Thanks Kostya and String, these were great answers.
>
> I can see how I can create my own subclass and use them instead of my
> the android classes.  My problem now is that it is the Preference
> Activity, through an intent extra, that knows the specific widget ID for
> which it is being displayed.  I don't see that the Preference or
> PreferenceCategory subclassses have access to the parent activity that
> caused them to be created.  Since Android is instantiating my subclasses
> for me, I don't see how I have a hook to pass the subclass the crucial
> piece of data required to reset its key - which is the whole purpose of
> this exercise.
>
> It looks like onPrepareAddPreference is probable the better place to
> reset the key than is addPreference simply because this is more of a
> preparation step anyway.  It's great to have multiple options!
>
> ...Jake
>
>
> >>>>> "KV" == Kostya Vasilyev <[email protected]> writes:
>
>    KV> Where your preference class needs to have the standard
>   KV> constructor, just like with views:
>
>   KV> public class MyPreferenceCategory extends PreferenceCategory {
>
>   KV>     public MyPreferenceCategory(Context context, AttributeSet attrs)
> {
>   KV>          super(context, attrs);
>   KV>     }
>
>   KV> }
>
>   KV> And here is another useful override:
>
>   KV>
> http://developer.android.com/reference/android/preference/PreferenceGroup.html#onPrepareAddPreference(android.preference.Preference
>   KV> )
>
>   KV> onPrepareAddPreference
>
>   KV> -- Kostya
>
>   KV> 2011/5/27 String <[email protected]>
>
>   >> In your XML settings-definition file, here's what you need. Just use:
>   >>
>   >> <com.my.package.PrefSubclass
>   >> android:key="pref_key"
>   >> ...
>   >> />
>   >>
>   >> where "com.my.package" is your package name, and PrefSubclass is the
> class
>   >> name of your Preference subclass. Use this instead of:
>   >>
>   >> <EditTextPreference
>   >> android:key="pref_key"
>   >> ...
>   >> />
>   >>
>   >> or whatever Preference class you're basing it off of.
>   >>
>   >> String
>   >>
>   >> --
>   >> 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
>

-- 
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