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


Java PreferenceScreen.addPreference方法代码示例

本文整理汇总了Java中android.support.v7.preference.PreferenceScreen.addPreference方法的典型用法代码示例。如果您正苦于以下问题:Java PreferenceScreen.addPreference方法的具体用法?Java PreferenceScreen.addPreference怎么用?Java PreferenceScreen.addPreference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.preference.PreferenceScreen的用法示例。


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

示例1: initSettings

import android.support.v7.preference.PreferenceScreen; //导入方法依赖的package包/类
private void initSettings(){
    PreferenceScreen screen = getPreferenceScreen();

    for(int i = 0; i < courses.size(); i++){
        
        //Add all courses as a checkbox
        CheckBoxPreference cbp = new CheckBoxPreference(getContext());
        cbp.setPersistent(false);
        cbp.setTitle(courses.get(i).getCourseCode());
        cbp.setKey("" + courses.get(i).getId());
        cbp.setViewId(i);
        cbp.setOnPreferenceClickListener(this);

        if (courses.get(i).isFavorite()) {
            cbp.setChecked(true);
        }

        checkBoxes.add(cbp);
        screen.addPreference(cbp);
    }
}
 
开发者ID:andrmos,项目名称:imber,代码行数:22,代码来源:SettingFavoriteCourseFragment.java

示例2: onCreatePreferences

import android.support.v7.preference.PreferenceScreen; //导入方法依赖的package包/类
@Override
public void onCreatePreferences(Bundle bundle, String rootkey) {
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
            getPreferenceManager().getContext());
    setPreferenceScreen(preferenceScreen);

    final Context preferenceContext = getPreferenceManager().getContext();
    for (UserRestriction restriction : UserRestriction.ALL_USER_RESTRICTIONS) {
        DpcSwitchPreference preference = new DpcSwitchPreference(preferenceContext);
        preference.setTitle(restriction.titleResId);
        preference.setKey(restriction.key);
        preference.setOnPreferenceChangeListener(this);
        preferenceScreen.addPreference(preference);
    }

    updateAllUserRestrictions();
    constrainPerferences();
}
 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:19,代码来源:UserRestrictionsDisplayFragment.java

示例3: onCreatePreferences

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

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
            getContext());

    // Get our screen which is created in Skin SettingsFragment
    PreferenceScreen screen = getPreferenceScreen();

    // Get profile preference
    PreferenceCategory category = (PreferenceCategory) screen.findPreference(KEY_PROFILE);

    // If category exists, we should add mole mapper specific things. If not, that means we
    // are not consented so we have no data to set.
    if(category != null)
    {
        // Occupation Preference
        Preference checkBoxPref = new Preference(screen.getContext());
        checkBoxPref.setKey(KEY_PROFILE_PROFESSION);
        checkBoxPref.setTitle(R.string.profession);
        checkBoxPref.setSummary(R.string.profession_unknown); // Set to prevent a "jump" when first entering the screen
        category.addPreference(checkBoxPref);
    }

    // Create the app category to place out two rpefs
    PreferenceCategory appCategory = new PreferenceCategory(screen.getContext());
    appCategory.setKey(KEY_APP);
    appCategory.setTitle(R.string.settings_app);
    appCategory.setOrder(1);
    screen.addPreference(appCategory);

    // Generate values for the mole naming convention pref
    MoleNameHelper.Gender[] values = MoleNameHelper.Gender.values();
    String[] entries = new String[values.length];
    String[] entryValues = new String[values.length];
    for(int i = 0; i < values.length; i++)
    {
        MoleNameHelper.Gender gender = values[i];
        entries[i] = getString(gender.getNameResourceId());
        entryValues[i] = Integer.toString(i);
    }

    // Create ListPreference and add to "App" category
    String defaultNamingConvention = Integer.toString(MoleNameHelper.Gender.RANDOM.ordinal());
    ListPreference namingConventionPref = new ListPreference(screen.getContext());
    namingConventionPref.setTitle(R.string.settings_app_mole_name_scheme);
    namingConventionPref.setKey(KEY_APP_MOLE_NAMING);
    namingConventionPref.setDefaultValue(defaultNamingConvention);
    namingConventionPref.setEntries(entries);
    namingConventionPref.setEntryValues(entryValues);
    namingConventionPref.setDialogTitle(R.string.settings_app_mole_name_scheme);
    String currentNamingConvInt = sharedPreferences.getString(KEY_APP_MOLE_NAMING,
            defaultNamingConvention);
    int currentNamingOrdinal = Integer.parseInt(currentNamingConvInt);
    namingConventionPref.setSummary(values[currentNamingOrdinal].getNameResourceId());
    appCategory.addPreference(namingConventionPref);
}
 
开发者ID:ResearchStack,项目名称:MoleMapperAndroid,代码行数:60,代码来源:MoleMapperSettingsFragment.java


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