Example usage for android.content.res Resources getTextArray

List of usage examples for android.content.res Resources getTextArray

Introduction

In this page you can find the example usage for android.content.res Resources getTextArray.

Prototype

@NonNull
public CharSequence[] getTextArray(@ArrayRes int id) throws NotFoundException 

Source Link

Document

Return the styled text array associated with a particular resource ID.

Usage

From source file:com.android.email.activity.setup.MailboxSettings.java

/**
 * Setup the entries and entry values for the sync lookback preference
 * @param context the caller's context/*from w w  w . jav  a 2  s  .  c o  m*/
 * @param pref a ListPreference to be set up
 * @param maxLookback The maximum lookback allowed, or 0 if no max.
 * @param showWithDefault Whether to show the version with default, or without.
 */
public static void setupLookbackPreferenceOptions(final Context context, final ListPreference pref,
        final int maxLookback, final boolean showWithDefault) {
    final Resources resources = context.getResources();
    // Load the complete list of entries/values
    CharSequence[] entries;
    CharSequence[] values;
    final int offset;
    if (showWithDefault) {
        entries = resources.getTextArray(R.array.account_settings_mail_window_entries_with_default);
        values = resources.getTextArray(R.array.account_settings_mail_window_values_with_default);
        offset = 1;
    } else {
        entries = resources.getTextArray(R.array.account_settings_mail_window_entries);
        values = resources.getTextArray(R.array.account_settings_mail_window_values);
        offset = 0;
    }
    // If we have a maximum lookback policy, enforce it
    if (maxLookback > 0) {
        final int size = maxLookback + offset;
        entries = Arrays.copyOf(entries, size);
        values = Arrays.copyOf(values, size);
    }
    // Set up the preference
    pref.setEntries(entries);
    pref.setEntryValues(values);
    pref.setSummary(pref.getEntry());
}