Example usage for android.preference MultiSelectListPreference getEntries

List of usage examples for android.preference MultiSelectListPreference getEntries

Introduction

In this page you can find the example usage for android.preference MultiSelectListPreference getEntries.

Prototype

public CharSequence[] getEntries() 

Source Link

Document

The list of entries to be shown in the list in subsequent dialogs.

Usage

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

/**
 * Set the preference's value(s) as its summary.
 *//*  ww w  .  j a  va  2 s  .c  o m*/
protected void setSummary(Preference pref) {
    SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
    if (pref instanceof RingtonePreference) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) {
            Ringtone tone = RingtoneManager.getRingtone(a, Uri.parse(val));
            if (tone != null) {
                pref.setSummary(tone.getTitle(a));
            }
        } else {
            pref.setSummary(R.string.none);
        }
    } else if (pref instanceof MultiSelectListPreference) {
        Set<String> vals = prefs.getStringSet(pref.getKey(), null);
        if (vals != null) {
            if (!vals.isEmpty()) {
                MultiSelectListPreference multi = (MultiSelectListPreference) pref;
                IntList indexList = new ArrayIntList(vals.size());
                for (String val : vals) { // find selected entry indexes
                    int i = multi.findIndexOfValue(val);
                    if (i >= 0) {
                        indexList.add(i);
                    }
                }
                int[] indexes = indexList.toArray();
                Arrays.sort(indexes); // to display in same order as dialog
                pref.setSummary(TextUtils.join(getString(R.string.delimiter),
                        Elements.slice(multi.getEntries(), indexes)));
            } else {
                pref.setSummary(R.string.none);
            }
        }
    } else if (pref instanceof EditTextPreference) {
        pref.setSummary(prefs.getString(pref.getKey(), null));
    } else if (pref.getClass() == Preference.class) {
        String val = prefs.getString(pref.getKey(), null);
        if (!TextUtils.isEmpty(val)) { // don't clear existing summary
            pref.setSummary(val);
        }
    }
}