本文整理匯總了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);
}
}
示例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();
}
示例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);
}