Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my application I have the similar task to show second-level <code>PreferencesScreen</code> programmatically. What I did:</p> <ol> <li><p>In <code>preferences.xml</code> I assigned a key to <code>PreferencesScreen</code> I want to show (as shown in the question).</p></li> <li><p>To show <code>PreferencesScreen</code> I wrote:</p> <pre><code>final Intent preferencesActivity = new Intent(getBaseContext(), MyPreferencesActivity.class); preferencesActivity.putExtra("PREFERENCE_SCREEN_KEY", "key_of_preference_screen_to_show"); startActivity(preferencesActivity); </code></pre></li> <li><p>Then in my PreferenceActivity class in method <code>onCreate</code> the following code was added:</p> <pre><code>final Intent intent = getIntent(); final String startScreen = intent.getStringExtra("PREFERENCE_SCREEN_KEY"); if (startScreen != null) { getIntent().removeExtra("PREFERENCE_SCREEN_KEY"); final Preference preference = findPreference(startScreen); final PreferenceScreen preferenceScreen = getPreferenceScreen(); final ListAdapter listAdapter = preferenceScreen.getRootAdapter(); final int itemsCount = listAdapter.getCount(); int itemNumber; for (itemNumber = 0; itemNumber &lt; itemsCount; ++itemNumber) { if (listAdapter.getItem(itemNumber).equals(preference)) { preferenceScreen.onItemClick(null, null, itemNumber, 0); break; } } } </code></pre></li> </ol> <p>One remark... Not only second-level <code>PreferencesScreen</code>, but the whole preferences hierarchy was loaded here. So, if you press <code>Back</code> button, the first (parent) <code>PreferencesScreen</code> will appear. In my case that was exactly what I needed. Not sure about yours.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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