本文整理汇总了Java中android.preference.MultiSelectListPreference.setTitle方法的典型用法代码示例。如果您正苦于以下问题:Java MultiSelectListPreference.setTitle方法的具体用法?Java MultiSelectListPreference.setTitle怎么用?Java MultiSelectListPreference.setTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.preference.MultiSelectListPreference
的用法示例。
在下文中一共展示了MultiSelectListPreference.setTitle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpUnitTypePrefs
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
/**
* Helper Class to setup the default Unit Type preference list in code
*/
private void setUpUnitTypePrefs() {
PreferenceScreen screen = getPreferenceScreen();
MultiSelectListPreference listPref = new MultiSelectListPreference(super.getActivity());
listPref.setOrder(0);
listPref.setDialogTitle(R.string.unit_select_title);
listPref.setKey(UNIT_TYPE_PREF_KEY);
listPref.setSummary(R.string.unit_select_summary);
listPref.setTitle(R.string.unit_select_title);
listPref.setEntries(getUnitTypeNameArray(getResources()));
String[] keyArray = getUnitTypeKeyArray(getResources());
listPref.setEntryValues(keyArray);
final Set<String> result = new HashSet<>();
Collections.addAll(result, keyArray);
listPref.setDefaultValue(result);
screen.addPreference(listPref);
}
示例2: addAccountsPreference
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void addAccountsPreference() {
final String[] accounts = GmailExtension.getAllAccountNames(this);
Set<String> allAccountsSet = new HashSet<String>();
allAccountsSet.addAll(Arrays.asList(accounts));
MultiSelectListPreference accountsPreference = new MultiSelectListPreference(this);
accountsPreference.setKey(GmailExtension.PREF_ACCOUNTS);
accountsPreference.setTitle(R.string.pref_gmail_accounts_title);
accountsPreference.setEntries(accounts);
accountsPreference.setEntryValues(accounts);
accountsPreference.setDefaultValue(allAccountsSet);
mFragment.getPreferenceScreen().addPreference(accountsPreference);
Preference.OnPreferenceChangeListener accountsChangeListener
= new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int numSelected = 0;
int numTotal = accounts.length;
try {
//noinspection unchecked
Set<String> selectedAccounts = (Set<String>) value;
if (selectedAccounts != null) {
numSelected = selectedAccounts.size();
}
} catch (ClassCastException ignored) {
}
preference.setSummary(getResources().getQuantityString(
R.plurals.pref_gmail_accounts_summary_template,
numTotal, numSelected, numTotal));
return true;
}
};
accountsPreference.setOnPreferenceChangeListener(accountsChangeListener);
accountsChangeListener.onPreferenceChange(accountsPreference,
PreferenceManager
.getDefaultSharedPreferences(this)
.getStringSet(accountsPreference.getKey(), allAccountsSet));
}
示例3: addAccountsPreference
import android.preference.MultiSelectListPreference; //导入方法依赖的package包/类
private void addAccountsPreference() {
final String[] accounts = GmailExtension.getAllAccountNames(this);
Set<String> allAccountsSet = new HashSet<String>();
allAccountsSet.addAll(Arrays.asList(accounts));
MultiSelectListPreference accountsPreference = new MultiSelectListPreference(this);
accountsPreference.setKey(GmailExtension.PREF_ACCOUNTS);
accountsPreference.setTitle(R.string.pref_gmail_accounts_title);
accountsPreference.setEntries(accounts);
accountsPreference.setEntryValues(accounts);
accountsPreference.setDefaultValue(allAccountsSet);
getPreferenceScreen().addPreference(accountsPreference);
Preference.OnPreferenceChangeListener accountsChangeListener
= new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int numSelected = 0;
int numTotal = accounts.length;
try {
//noinspection unchecked
Set<String> selectedAccounts = (Set<String>) value;
if (selectedAccounts != null) {
numSelected = selectedAccounts.size();
}
} catch (ClassCastException ignored) {
}
preference.setSummary(getResources().getQuantityString(
R.plurals.pref_gmail_accounts_summary_template,
numTotal, numSelected, numTotal));
return true;
}
};
accountsPreference.setOnPreferenceChangeListener(accountsChangeListener);
accountsChangeListener.onPreferenceChange(accountsPreference,
PreferenceManager
.getDefaultSharedPreferences(this)
.getStringSet(accountsPreference.getKey(), allAccountsSet));
}