I'm trying to create a preferences screen with a dynamic list of entries, and when clicking each of them, I have another screen of preferences. As an example, think of a list of mail accounts and each one having their account settings available.
While I can create the nesting I want using just PreferenceScreens
, this can't easily be scaled to multiple entries without creating the sub preferences structure in code for each one.
I see several different variations throughout the Android UI.
Is there a recomended way to create such a structure as this?
Possibilites include:
Separate, independant activities
Works but is messy in my opinionNested, code created PreferenceScreens
Pain in the ass for maintainence and it means the preferences are no longer stored as XML fragmentsNested, inflated PreferenceScreens
I can't find a way to expand another XML file into a sub treeOne "sub" PreferenceScreen that is shown using setPreferenceScreen() for each one
I can't find a way to hide the "template" PreferenceScreen and it breaks the navigation.
Sample XML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/prefs_title">
<EditTextPreference android:key="add_console"
android:title="@string/prefs_add_console"></EditTextPreference>
<PreferenceCategory android:title="@string/prefs_consoles_title"
android:key="list">
<PreferenceScreen android:summary="http://cctv.icode.co.uk/"
android:title="iCode Console">
</PreferenceScreen>
<PreferenceScreen android:summary="http://test.icode.co.uk/"
android:title="Test Console">
</PreferenceScreen>
</PreferenceCategory>
<PreferenceScreen android:title="Console (template)"
android:key="console">
<EditTextPreference android:title="@string/prefs_console_host"
android:summary="@string/prefs_not_set" android:key="host"></EditTextPreference>
<CheckBoxPreference android:title="@string/prefs_console_auth"
android:summary="@string/prefs_console_auth_summary" android:key="auth"></CheckBoxPreference>
<EditTextPreference android:shouldDisableView="true"
android:title="@string/prefs_console_authuser" android:key="authuser"
android:dependency="auth" android:summary="@string/prefs_not_set"></EditTextPreference>
<EditTextPreference android:title="@string/prefs_console_authpass"
android:key="authpass" android:dependency="auth" android:summary="@string/prefs_not_set"></EditTextPreference>
<CheckBoxPreference android:title="@string/prefs_console_pair"
android:summary="@string/prefs_console_pair_summary" android:key="pair"></CheckBoxPreference>
</PreferenceScreen>
</PreferenceScreen>
I want the entries under list
to be dynamic and show the console
preferences under each.
All other ideas welcome.
Thanks