Example usage for android.preference ListPreference ListPreference

List of usage examples for android.preference ListPreference ListPreference

Introduction

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

Prototype

public ListPreference(Context context) 

Source Link

Usage

From source file:com.airflo.preferences.ListPreferenceActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override/*from  w w  w  . j av  a2  s .com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    root = getPreferenceManager().createPreferenceScreen(this);

    //Array of sorting preference keys to be included. 
    //SortType must be specified in bookitems.xml!
    String[] sortValues = new String[] { "number", "date;starttime", "site;date;starttime", "duration",
            "maxheight", "maxvario", "starttype;date;starttime" };
    //Generate according Entry Strings.
    String[] sortEntries = new String[sortValues.length];
    for (int i = 0; i < sortEntries.length; i++)
        sortEntries[i] = sortKeyToString(sortValues[i]);

    //Make sorting category
    PreferenceCategory cat = new PreferenceCategory(this);
    cat.setTitle(R.string.list_pref_cat_sort_title);
    root.addPreference(cat);
    final ListPreference listPref = new ListPreference(this);
    listPref.setKey("list_pref_sort");
    listPref.setEntries(sortEntries);
    listPref.setEntryValues(sortValues);
    listPref.setDialogTitle(R.string.list_pref_sort_criterium);
    listPref.setSummary(sortKeyToString(root.getSharedPreferences().getString("list_pref_sort", "number")));
    listPref.setTitle(R.string.list_pref_sort_criterium);
    cat.addPreference(listPref);
    listPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            listPref.setSummary(sortKeyToString((String) newValue));
            return true;
        }
    });
    final ListPreference orderPref = new ListPreference(this);
    orderPref.setKey("list_pref_order");
    orderPref.setEntries(new String[] { OnlyContext.rString("list_pref_sort_ascending"),
            OnlyContext.rString("list_pref_sort_decending") });
    orderPref.setEntryValues(new String[] { "list_pref_sort_ascending", "list_pref_sort_decending" });
    orderPref.setDialogTitle(R.string.list_pref_sort_sequence);
    orderPref.setSummary(OnlyContext
            .rString(root.getSharedPreferences().getString("list_pref_order", "list_pref_sort_decending")));
    orderPref.setTitle(R.string.list_pref_sort_sequence);
    cat.addPreference(orderPref);
    orderPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            orderPref.setSummary(OnlyContext.rString((String) newValue));
            return true;
        }
    });

    //Make item categories
    addManyListItems(R.string.list_pref_cat1_title, "listhead", 3);
    addManyListItems(R.string.list_pref_cat2_title, "listsub", 3);

    this.setPreferenceScreen(root);
}

From source file:com.airflo.preferences.ListPreferenceActivity.java

/**
 * Add one slider preference to the category.
 * @param cat//from   w ww  .  j  av a  2s  .c  o  m
 * @param key
 * @param title
 */
private void addOneListItem(PreferenceCategory cat, String key, String title) {
    final ListPreference listPref = new ListPreference(this);
    listPref.setKey(key);
    listPref.setEntries(FlightData.identis.getPrefListChars(true));
    listPref.setEntryValues(FlightData.identis.getPrefListChars(false));
    listPref.setDialogTitle(title);
    listPref.setSummary(
            FlightData.identis.getIdenti(root.getSharedPreferences().getString(key, "empty")).getStringRep());
    listPref.setTitle(title);
    cat.addPreference(listPref);
    listPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            listPref.setSummary(FlightData.identis.getIdenti((String) newValue).getStringRep());
            return true;
        }
    });
}

From source file:com.csipsimple.wizards.impl.Betamax.java

/**
 * {@inheritDoc}//from  w  w w . ja v  a  2 s.c  o  m
 */
@Override
public void fillLayout(final SipProfile account) {
    super.fillLayout(account);

    accountUsername.setTitle(R.string.w_advanced_caller_id);
    accountUsername.setDialogTitle(R.string.w_advanced_caller_id_desc);

    boolean recycle = true;
    providerListPref = (ListPreference) findPreference(PROVIDER_LIST_KEY);
    if (providerListPref == null) {
        Log.d(THIS_FILE, "Create new list pref");
        providerListPref = new ListPreference(parent);
        providerListPref.setKey(PROVIDER_LIST_KEY);
        recycle = false;
    } else {
        Log.d(THIS_FILE, "Recycle existing list pref");
    }

    CharSequence[] v = new CharSequence[providers.size()];
    int i = 0;
    for (String pv : providers.keySet()) {
        v[i] = pv;
        i++;
    }

    providerListPref.setEntries(v);
    providerListPref.setEntryValues(v);
    providerListPref.setKey(PROVIDER);
    providerListPref.setDialogTitle("Provider");
    providerListPref.setTitle("Provider");
    providerListPref.setSummary("Betamax clone provider");
    providerListPref.setDefaultValue("12VoIP");

    if (!recycle) {
        addPreference(providerListPref);
    }
    hidePreference(null, SERVER);

    String domain = account.getDefaultDomain();
    if (domain != null) {
        for (Entry<String, String[]> entry : providers.entrySet()) {
            String[] val = entry.getValue();
            if (val[0].equalsIgnoreCase(domain)) {
                Log.d(THIS_FILE, "Set provider list pref value to " + entry.getKey());
                providerListPref.setValue(entry.getKey());
                break;
            }
        }
    }
    Log.d(THIS_FILE, providerListPref.getValue());

    // Get wizard specific row
    customWizardText = (TextView) parent.findViewById(R.id.custom_wizard_text);
    customWizard = (LinearLayout) parent.findViewById(R.id.custom_wizard_row);

    updateAccountInfos(account);
}