Note that there are some explanatory texts on larger screens.

plurals
  1. PONested PreferenceScreens under a dynamic list of preferences on Android
    text
    copied!<p>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.</p> <p>While I can create the nesting I want using just <code>PreferenceScreens</code>, this can't easily be scaled to multiple entries without creating the sub preferences structure in code for each one.</p> <p>I see several different variations throughout the Android UI.</p> <p>Is there a recomended way to create such a structure as this?</p> <p>Possibilites include:</p> <ol> <li><p>Separate, independant activities<br> Works but is messy in my opinion</p></li> <li><p>Nested, code created PreferenceScreens<br> Pain in the ass for maintainence and it means the preferences are no longer stored as XML fragments</p></li> <li><p>Nested, inflated PreferenceScreens<br> I can't find a way to expand another XML file into a sub tree</p></li> <li><p>One "sub" PreferenceScreen that is shown using setPreferenceScreen() for each one<br> I can't find a way to hide the "template" PreferenceScreen and it breaks the navigation.</p></li> </ol> <p>Sample XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/prefs_title"&gt; &lt;EditTextPreference android:key="add_console" android:title="@string/prefs_add_console"&gt;&lt;/EditTextPreference&gt; &lt;PreferenceCategory android:title="@string/prefs_consoles_title" android:key="list"&gt; &lt;PreferenceScreen android:summary="http://cctv.icode.co.uk/" android:title="iCode Console"&gt; &lt;/PreferenceScreen&gt; &lt;PreferenceScreen android:summary="http://test.icode.co.uk/" android:title="Test Console"&gt; &lt;/PreferenceScreen&gt; &lt;/PreferenceCategory&gt; &lt;PreferenceScreen android:title="Console (template)" android:key="console"&gt; &lt;EditTextPreference android:title="@string/prefs_console_host" android:summary="@string/prefs_not_set" android:key="host"&gt;&lt;/EditTextPreference&gt; &lt;CheckBoxPreference android:title="@string/prefs_console_auth" android:summary="@string/prefs_console_auth_summary" android:key="auth"&gt;&lt;/CheckBoxPreference&gt; &lt;EditTextPreference android:shouldDisableView="true" android:title="@string/prefs_console_authuser" android:key="authuser" android:dependency="auth" android:summary="@string/prefs_not_set"&gt;&lt;/EditTextPreference&gt; &lt;EditTextPreference android:title="@string/prefs_console_authpass" android:key="authpass" android:dependency="auth" android:summary="@string/prefs_not_set"&gt;&lt;/EditTextPreference&gt; &lt;CheckBoxPreference android:title="@string/prefs_console_pair" android:summary="@string/prefs_console_pair_summary" android:key="pair"&gt;&lt;/CheckBoxPreference&gt; &lt;/PreferenceScreen&gt; &lt;/PreferenceScreen&gt; </code></pre> <p>I want the entries under <code>list</code> to be dynamic and show the <code>console</code> preferences under each.</p> <p>All other ideas welcome.</p> <p>Thanks </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload