本文整理匯總了Java中android.preference.PreferenceScreen.getPreference方法的典型用法代碼示例。如果您正苦於以下問題:Java PreferenceScreen.getPreference方法的具體用法?Java PreferenceScreen.getPreference怎麽用?Java PreferenceScreen.getPreference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.preference.PreferenceScreen
的用法示例。
在下文中一共展示了PreferenceScreen.getPreference方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setKeys
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
private void setKeys(PreferenceScreen screen)
{
for(int i = 0; i < screen.getPreferenceCount(); i++)
{
Preference preference = screen.getPreference(i);
String key = server + ";" + preference.getKey();
preference.setKey(key);
if(preference instanceof EditIntPreference)
((EditIntPreference)preference).setInt(preference.getSharedPreferences().getInt(key, -1));
else if(preference instanceof EditTextPreference)
((EditTextPreference)preference).setText(preference.getSharedPreferences().getString(key, null));
else if(preference instanceof ListPreference)
((ListPreference)preference).setValue(preference.getSharedPreferences().getString(key, null));
else if(preference instanceof CheckBoxPreference)
((CheckBoxPreference)preference).setChecked(preference.getSharedPreferences().getBoolean(key, false));
if(preference instanceof PreferenceScreen)
setKeys((PreferenceScreen)preference);
}
}
示例2: onCreate
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_infos);
setHasOptionsMenu(true);
findPreference("version").setSummary(getString(R.string.version, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
PreferenceScreen prefScreen = getPreferenceScreen();
for (int i = 0; i < prefScreen.getPreferenceCount(); i++) {
Preference pref = prefScreen.getPreference(i);
if (!BuildConfig.DEBUG && pref.getKey().startsWith("debug_"))
prefScreen.removePreference(pref);
}
if (BuildConfig.DEBUG) {
findPreference("debug_send_notification").setSummary("Package name: " + BuildConfig.APPLICATION_ID);
findPreference("debug_send_notification").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
((NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
new NotificationCompat.Builder(getActivity())
.setSmallIcon(R.drawable.info)
.setContentTitle("Test Notification")
.setContentText("Use " + BuildConfig.APPLICATION_ID + " as the package name to test your actions")
.build());
return true;
}
});
}
}
示例3: updateSelected
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
private void updateSelected() {
final PreferenceScreen screen = getPreferenceScreen();
final int count = screen.getPreferenceCount();
for (int index = 0; index < count; index++) {
final Preference preference = screen.getPreference(index);
if (preference instanceof KeyboardThemePreference) {
final KeyboardThemePreference pref = (KeyboardThemePreference)preference;
final boolean selected = (mSelectedThemeId == pref.mThemeId);
pref.setSelected(selected);
}
}
}
示例4: setDescriptions
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
private void setDescriptions(PreferenceScreen screen)
{
for(int i = 0; i < screen.getPreferenceCount(); i++)
{
Preference preference = screen.getPreference(i);
setSingleDescription(preference);
if(preference instanceof PreferenceScreen)
setDescriptions((PreferenceScreen)preference);
}
}
示例5: setDescriptions
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
private void setDescriptions(PreferenceScreen screen)
{
for(int i = 0; i < screen.getPreferenceCount(); i++)
{
Preference preference = screen.getPreference(i);
if(preference instanceof EditTextPreference)
preference.setSummary(((EditTextPreference)preference).getText());
if(preference instanceof PreferenceScreen)
setDescriptions((PreferenceScreen)preference);
}
}
示例6: onCreate
import android.preference.PreferenceScreen; //導入方法依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Bind the view with presenter
presenter = new Presenter(this);
presenter.getInitialize(getArguments());
PreferenceScreen preferenceScreen = getPreferenceScreen();
//START loop to set listener on Preferences
// Set "this" to listen for all preference click/change listener for all preferences
for (int i = 0, size = preferenceScreen.getPreferenceCount(); i < size; i++) {
Preference preference = preferenceScreen.getPreference(i);
preference.setOnPreferenceClickListener(this);
preference.setOnPreferenceChangeListener(this);
// If this is a preference category, make sure to go through all the subpreferences as well.
if (preference instanceof PreferenceCategory) {
Stack<PreferenceCategory> stack = new Stack<>();
stack.push((PreferenceCategory) preference);
do {
PreferenceCategory category = stack.pop();
for (int x = 0, xSize = category.getPreferenceCount(); x < xSize; x++) {
Preference subPref = category.getPreference(x);
subPref.setOnPreferenceChangeListener(this);
subPref.setOnPreferenceClickListener(this);
if (subPref instanceof PreferenceCategory) {
stack.push((PreferenceCategory) subPref);
}
}
}
while (!stack.isEmpty());
}
} //END loop to set listener on Preferences
//This will update the state of the Settings view
presenter.handlePreferences();
}