2

My Google-Fu is failing this Android newbie today.

Does anybody know of a good example showing how to launch an intent from a PreferenceScreen?

Something like:

    <PreferenceScreen
        android:key="preference_some_new_layout"
        android:title="@string/pref_some_title">

            <intent android:action="????" /> 

    </PreferenceScreen>

I want to show a custom LinearLayout that allows me to set some semi-complex preferences.

What is the best way to go about this?

Thanks, wTs

Wonko the Sane
  • 10,623
  • 8
  • 67
  • 92
  • This isn't my answer, but it answers your original question, about how to launch an intent from a PreferenceScreen in xml: http://stackoverflow.com/a/3751306/582004 – liucheia May 02 '13 at 23:50

1 Answers1

5

I've used a custom dialog box before for a preference. Is this sort of what you need? Here is an example from my open source app.

And here is the XML to add the preference to a PreferenceScreen.

<net.mandaria.tippytipper.preferences.DecimalPreference
                        android:key="exclude_tax"
                android:title="Tax Rate to Exclude"
                android:summary="The tax rate to exclude when calculating tip"
                android:dialogMessage="Tax Rate"
                android:defaultValue="0"
                android:dependency="enable_exclude_tax_rate"
                />

This will let you produce complex preferences in a DialogPreference (you might be able to swap this out if you don't need a Dialog, someone else will have to fill that in for you because I've never tried) that look like this:

alt text

Bryan Denny
  • 27,363
  • 32
  • 109
  • 125
  • I wrote a little more about it here: http://www.bryandenny.com/index.php/2010/05/25/what-i-learned-from-writing-my-first-android-application/ But basically you need to make sure you persist your values i.e. mValue = getPersistedInt(mDefault); or persistInt(value + mMin); – Bryan Denny Nov 10 '10 at 17:07
  • Amazing examples about custom preferences, thanks Bryan I learn a lot :-D thanks for sharing code – rubdottocom Nov 14 '11 at 17:32