Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: prevent preference dialog for preference which must be loaded over the network
    primarykey
    data
    text
    <p>My app has a ListPreference, whose entries come from a network API. In my PreferenceActivity's onCreate(), I spawn a background thread which makes the API call and then populates the entries of the ListPreference after one or two seconds.</p> <p>If the user clicks the ListPreference button on the preference screen before the options have been downloaded, I want to prevent the preference dialog from showing and instead notify the user that the list of options is still being loaded.</p> <p>I suspect that correct approach is to override the OnPreferenceClickListener, like this:</p> <pre><code>ListPreference dpref = (ListPreference) findPreference("debug"); String[] s = {"one", "two", "three"}; dpref.setEntries(s); dpref.setEntryValues(s); dpref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Toast.makeText(this, "hi there", Toast.LENGTH_SHORT).show(); return true; } }); </code></pre> <p>The toast gets shown, but the ListPreference chooser dialog is shown as well. The <a href="http://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener.html" rel="nofollow">OnPreferenceClickListener documentation</a> says that onPreferenceClick should return <code>true</code> if the click was handled, but returning <code>false</code> has the same result.</p> <p>How do I prevent the preference dialog from showing?</p> <p>Is there a better way to handle preferences whose options must be downloaded before viewing?</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.
 

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