简体   繁体   中英

Showing ListPreference from the main activity

I have a

SettingsActivity extends PreferenceActivity

SettingsActivity is populated by addPreferencesFromResource(R.xml.preferences) where I have my custom

SMode extends ListPreference
<PreferenceCategory
    android:key="key"
    android:persistent="false"
    android:title="Title" >

<package.SMode
    android:title="Mode"
        android:entries="@array/1"
        android:entryValues="@array/2"
    android:key="prefSMode"
                android:summary="Sum"
    />

What I want to do is to show this ListPreference dialog by clicking a button outside the PreferenceActivity. In other words a shortcut for setting "mode" without leaving my main acitivy and going to preferences.

I also need it to work with APII level < 11.

Is it possible to do that?

Use PreferenceFragment see example here .
You can use it inside and FragmentActivity or in DialogFragment .
But if you need to use below API 11 consider a custom view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM