Android: ListPreference hide/disable value

Viewed 6930

I'm generating a listPreference dialog based on xml (entries and entryValues).

<string-array name="listArray">
    <item>Title (A-Z)</item>
    <item>Title (Z-A)</item>
    <item>Visits (default)</item>
    <item>Date</item>
    <item>Manual</item>
</string-array> 
<string-array name="listValues">
   <item>titleASC</item>
   <item>titleDESC</item>
   <item>visitsSort</item>
   <item>createSort</item>
   <item>manualSort</item>
</string-array>

I want to hide/disable some of the entries (for example: Manual) based on some other parameters.

I understand it should be inside this scope:

Preference sorted = (Preference) findPreference(OPT_SORT);

        sorted.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {

                if (params) {
                    What should i put here to hide/disable some of the entries?
                }

                return true;
            }
        });

Thank you!

EDIT:

Best solution I found is to load a different set of Entries and EntryValues. On Preference class (onCreate):

ListPreference sortBy = (ListPreference) findPreference(OPT_SORT);
        if (isTabletDevice()) {
            sortBy.setEntries(getResources().getStringArray(R.array.HClistArray));
            sortBy.setEntryValues(getResources().getStringArray(R.array.HClistValues));
        }

Hope this helps anyone! :)

2 Answers
Related