当前位置: 首页>>代码示例>>Java>>正文


Java MultiSelectListPreference类代码示例

本文整理汇总了Java中android.support.v14.preference.MultiSelectListPreference的典型用法代码示例。如果您正苦于以下问题:Java MultiSelectListPreference类的具体用法?Java MultiSelectListPreference怎么用?Java MultiSelectListPreference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MultiSelectListPreference类属于android.support.v14.preference包,在下文中一共展示了MultiSelectListPreference类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreatePreferences

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {

    // Add preferences, defined in the XML file in res->xml->preferences.xml
    addPreferencesFromResource(R.xml.preferences);

    //set the summaries for the different preferences for the first time
    SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
    PreferenceScreen prefScreen = getPreferenceScreen();
    int count = prefScreen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference p = prefScreen.getPreference(i);
        // You don't need to set up preference summaries for checkbox preferences because
        // they are already set up in xml using summaryOff and summary On
        if (!(p instanceof CheckBoxPreference) && !(p instanceof MultiSelectListPreference)) {
            String value = sharedPreferences.getString(p.getKey(), "");
            setPreferenceSummary(p, value);
        }
    }

    //attach listener to check for changes in the radius preference
    //because it should only contain only doubles and the code has to enforce this
    Preference preference = findPreference(getString(R.string.pref_radius_key));
    preference.setOnPreferenceChangeListener(this);
}
 
开发者ID:Jugendhackt,项目名称:Camera-warner,代码行数:26,代码来源:SettingsFragment.java

示例2: onCreatePreferences

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.settings);

    MultiSelectListPreference weightedPreference = (MultiSelectListPreference) findPreference("pref_weightedClasses");

    MultiSelectListPreference excludedPreference = (MultiSelectListPreference) findPreference("pref_excludedClasses");

    Course[] courses = new DataManager(getActivity()).getCourseGrades();

    CharSequence[] classes = new CharSequence[courses.length];
    for (int i = 0; i < courses.length; i++) {
        classes[i] = courses[i].title;
    }
    weightedPreference.setEntryValues(classes);
    weightedPreference.setEntries(classes);
    excludedPreference.setEntryValues(classes);
    excludedPreference.setEntries(classes);
}
 
开发者ID:project-manatee,项目名称:manatee-android,代码行数:20,代码来源:SettingsFragment.java

示例3: onPrepareDialogBuilder

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
/**
 * We set the AlertDialog to display a multi-choice list.  We register a listener: when the user
 * checks or un-checks values, we store the list of all selected values.
 */
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    super.onPrepareDialogBuilder(builder);
    final MultiSelectListPreference preference = getListPreference();
    if (preference.getEntries() != null && preference.getEntryValues() != null) {
        boolean[] checkedItems = getSelectedItems();
        builder.setMultiChoiceItems(preference.getEntries(), checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                mPreferenceChanged = true;
                if (isChecked) {
                    mNewValues.add(preference.getEntryValues()[which].toString());
                } else {
                    mNewValues.remove(preference.getEntryValues()[which].toString());
                }
            }
        });
        mNewValues.clear();
        mNewValues.addAll(preference.getValues());
    } else {
        throw new IllegalStateException("MultiSelectListPreference requires an entries array and an entryValues array.");
    }
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:26,代码来源:MultiSelectListPreferenceDialogFragmentCompat.java

示例4: setSwipeEdge

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
private void setSwipeEdge() {
    mSwipeEdge = (MultiSelectListPreference) findPreference(GlobalSetting.SWIPE_BACK_EDGE);
    int edge = GlobalSetting.getSwipeBackEdge();

    Set<String> edges = new HashSet<String>();
    StringBuilder summary = new StringBuilder();
    if ((edge & SwipeBackLayout.EDGE_LEFT) != 0) {
        edges.add(String.valueOf(SwipeBackLayout.EDGE_LEFT));
        summary.append(getResources().getString(R.string.swipe_edge_left)).append(" ");
    }
    if ((edge & SwipeBackLayout.EDGE_RIGHT) != 0) {
        edges.add(String.valueOf(SwipeBackLayout.EDGE_RIGHT));
        summary.append(getResources().getString(R.string.swipe_edge_right)).append(" ");
    }
    if ((edge & SwipeBackLayout.EDGE_BOTTOM) != 0) {
        edges.add(String.valueOf(SwipeBackLayout.EDGE_BOTTOM));
        summary.append(getResources().getString(R.string.swipe_edge_bottom)).append(" ");
    }
    mSwipeEdge.setValues(edges);
    mSwipeEdge.setSummary(summary.toString());
    mSwipeEdge.setOnPreferenceChangeListener(this);
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:23,代码来源:SettingFragment.java

示例5: getSelectedEntries

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
private Set<CharSequence> getSelectedEntries(@NonNull Set<String> values, @NonNull MultiSelectListPreference multilistPreference) {
    Set<CharSequence> labels = new HashSet<CharSequence>();
    for (String value : values) {
        int index = multilistPreference.findIndexOfValue(value);
        labels.add(multilistPreference.getEntries()[index]);
    }
    multilistPreference.setSummary(labels.toString());
    return labels;
}
 
开发者ID:nhocga1995s,项目名称:MyCalendar,代码行数:10,代码来源:SettingsActivity.java

示例6: onSharedPreferenceChanged

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    //get the preference that was changed
    Preference preference = findPreference(key);

    // Updates the summary for the preference if is not null
    if (null != preference) {
        // You don't need to set up preference summaries for checkbox preferences because
        // they are already set up in xml using summaryOff and summary On
        if (!(preference instanceof CheckBoxPreference) && !(preference instanceof MultiSelectListPreference)) {
            String value = sharedPreferences.getString(preference.getKey(), "");
            setPreferenceSummary(preference, value);
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:Camera-warner,代码行数:16,代码来源:SettingsFragment.java

示例7: updateAvailableNotifications

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public void updateAvailableNotifications() {
    MultiSelectListPreference list = (MultiSelectListPreference) getPreferenceScreen().findPreference(LibrusConstants.ENABLED_NOTIFICATION_TYPES);
    String[] labels = J8Arrays.stream(LibrusConstants.NOTIFICATION_TYPES)
            .map(type -> getResources().getIdentifier(type, "string", getContext().getPackageName()))
            .map(getResources()::getString)
            .toArray(String[]::new);

    Set<String> values = PreferenceManager.getDefaultSharedPreferences(getContext())
            .getStringSet(LibrusConstants.ENABLED_NOTIFICATION_TYPES, Sets.newHashSet(LibrusConstants.NOTIFICATION_TYPES));
    list.setValues(values);
    list.setEntryValues(LibrusConstants.NOTIFICATION_TYPES);
    list.setEntries(labels);
}
 
开发者ID:shymmq,项目名称:librus-client,代码行数:15,代码来源:SettingsFragment.java

示例8: bindPreferenceSummaryToValue

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
protected static void bindPreferenceSummaryToValue(Preference preference) {
    // Set the listener to watch for value changes.
    if (preference == null)
        return;
    preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);

    // Trigger the listener immediately with the preference's
    // current value.
    if (preference instanceof CheckBoxPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getBoolean(preference.getKey(),
                        false));
    } else if (preference instanceof SwitchPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getBoolean(preference.getKey(),
                        false));
    } else if (preference instanceof MultiSelectListPreference) {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getStringSet(preference.getKey(),
                        new HashSet<String>()));
    } else {
        sBindPreferenceSummaryToValueListener.onPreferenceChange(
                preference,
                PreferenceManager.getDefaultSharedPreferences(
                        preference.getContext()).getString(preference.getKey(),
                        ""));
    }
}
 
开发者ID:GreenSkinMonster,项目名称:hipda,代码行数:35,代码来源:BaseSettingFragment.java

示例9: onCreatePreferences

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    setPreferencesFromResource(R.xml.newperferences, rootKey);
    //NOTE the rest of this code in not necessary, used so you can display current value on the summary line.

    // Get a reference to the preferences, so we can dynamically update the preference screen summary info.
    mMultiSelectListPreference = (MultiSelectListPreference) getPreferenceScreen().findPreference("multiselect_key");
}
 
开发者ID:JimSeker,项目名称:saveData,代码行数:9,代码来源:PrefNewFrag.java

示例10: onDialogClosed

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
/**
 * If the user tapped on "ok", we update our Preference's selected values, based on the values
 * our alert dialog listener saved.
 * @param positiveResult true if the user tapped on "ok".
 */
public void onDialogClosed(boolean positiveResult) {
    MultiSelectListPreference preference = getListPreference();
    if (positiveResult && mPreferenceChanged) {
        Set<String> values = mNewValues;
        if (preference.callChangeListener(values)) {
            preference.setValues(values);
        }
    }
    mPreferenceChanged = false;
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:16,代码来源:MultiSelectListPreferenceDialogFragmentCompat.java

示例11: getSelectedItems

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
/**
 * @return a list of the checked/unchecked state of all the list entries.
 */
private boolean[] getSelectedItems() {
    MultiSelectListPreference preference = getListPreference();
    CharSequence[] entries = preference.getEntryValues();
    Set<String> values = preference.getValues();
    boolean[] result = new boolean[entries.length];
    for (int i = 0; i < entries.length; i++) {
        result[i] = values.contains(entries[i].toString());
    }
    return result;
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:14,代码来源:MultiSelectListPreferenceDialogFragmentCompat.java

示例12: onDisplayPreferenceDialog

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
/**
 * Displays preference dialogs which aren't supported by default in PreferenceFragmentCompat.
 *
 * @return true if we managed a preference which isn't supported by default, false otherwise.
 */
public static boolean onDisplayPreferenceDialog(PreferenceFragmentCompat preferenceFragmentCompat, Preference preference) {
    DialogFragment dialogFragment = (DialogFragment) preferenceFragmentCompat.getFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
    if (dialogFragment != null) return false;


    // Hack to allow a MultiSelectListPreference
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH
            && preference instanceof MultiSelectListPreference) {
        dialogFragment = MultiSelectListPreferenceDialogFragmentCompat.newInstance(preference.getKey());
    }
    // Hack to allow a PasswordPreference
    //else if (preference instanceof PasswordPreference) {
    //    dialogFragment = PasswordPreferenceDialogFragmentCompat.newInstance(preference.getKey());
    //}


    // We've created our own fragment:
    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(preferenceFragmentCompat, 0);
        dialogFragment.show(preferenceFragmentCompat.getFragmentManager(), FRAGMENT_TAG_DIALOG);
        return true;
    }


    return false;
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:32,代码来源:PreferenceFragmentCompatHack.java

示例13: getListPreference

import android.support.v14.preference.MultiSelectListPreference; //导入依赖的package包/类
private MultiSelectListPreference getListPreference() {
    return (MultiSelectListPreference) getPreference();
}
 
开发者ID:fei-ke,项目名称:ChipHellClient,代码行数:4,代码来源:MultiSelectListPreferenceDialogFragmentCompat.java


注:本文中的android.support.v14.preference.MultiSelectListPreference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。