本文整理汇总了Java中android.content.SharedPreferences.OnSharedPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SharedPreferences.OnSharedPreferenceChangeListener方法的具体用法?Java SharedPreferences.OnSharedPreferenceChangeListener怎么用?Java SharedPreferences.OnSharedPreferenceChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.SharedPreferences
的用法示例。
在下文中一共展示了SharedPreferences.OnSharedPreferenceChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
persistence = new Persistence(getActivity().getApplicationContext());
SharedPreferences.OnSharedPreferenceChangeListener spChanged = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// If the buy schedule has changed, cancel and recreate the alarms.
if (key.equals("preference_frequency")) {
try {
persistence.setLastBuyTime(0);
BuyScheduler.setAlarm(getActivity().getApplicationContext());
} catch (Exception e) {
//
}
}
}
};
PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()).registerOnSharedPreferenceChangeListener(spChanged);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
示例2: testRegisterListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void testRegisterListener(View view) {
String testValue = "myTestString";
final String testKey = "testR";
final SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Assert.assertEquals(testKey, key);
showSuccess();
}
};
getPreferences().registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
getPreferences().edit().putString(testKey, testValue).apply();
getPreferences().unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
示例3: onCreate
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
addPreferencesFromResource(R.xml.board_preferences);
mBoardTitlePreference = (EditTextPreference) findPreference(BoardUtils.BOARD_TITLE_KEY);
setBoardTitlePreference();
mListenerOptions = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case BoardUtils.BOARD_TITLE_KEY:
updateBoardTitlePreferenceSummary();
break;
case BoardUtils.CUSTOM_APP_KEY:
manageCustomAppPreference();
break;
}
}
};
mCustomAppPreference = findPreference(BoardUtils.CUSTOM_APP_PREF_KEY);
manageCustomAppPreference();
mCustomAppPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(getActivity(), MultiSelectRecyclerViewActivity.class);
getActivity().startActivity(intent);
return false;
}
});
}
示例4: onCreate
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Carrega preferences a partir de um XML
addPreferencesFromResource(R.xml.user_prefs);
// pega a Preference especifica do username
mUserNamePreference = (Preference) getPreferenceManager()
.findPreference(USERNAME);
// Define um listener para atualizar descricao ao modificar preferences
mListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
mUserNamePreference.setSummary(sharedPreferences.getString(
USERNAME, "Nada ainda"));
}
};
// Pega objeto SharedPreferences gerenciado pelo PreferenceManager para este Fragmento
SharedPreferences prefs = getPreferenceManager()
.getSharedPreferences();
// Registra listener no objeto SharedPreferences
prefs.registerOnSharedPreferenceChangeListener(mListener);
// Invoca callback manualmente para exibir username atual
//mListener.onSharedPreferenceChanged(prefs, USERNAME);
/**/
}
示例5: registerOnSharedPreferenceChangeListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangeListener() {
SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
boolean notifIsOn = sharedPreferences.getBoolean(getString(R.string.pref_title_new_message_notifications), true);
// TODO
// SwitchPreference notifSwitchPreference = (SwitchPreference) getFragmentManager().
if (notifIsOn) {
} else {
}
}
};
}
示例6: unregisterOnSharedPreferenceChangeListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
@Override
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener) {
delegate.unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
}
示例7: registerListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
androidSharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
示例8: unregisterOnSharedPreferenceChangeListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
_sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
}
示例9: unregisterPreferenceChangedListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
pref.unregisterOnSharedPreferenceChangeListener(value);
}
示例10: registerPreferenceChangedListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
pref.registerOnSharedPreferenceChangeListener(value);
}
示例11: unregisterListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void unregisterListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
示例12: registerOnSharedPreferenceChangeListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
/**
* Register SharedPreferences change listener
*
* @param listener listener object of OnSharedPreferenceChangeListener
*/
public void registerOnSharedPreferenceChangeListener(
SharedPreferences.OnSharedPreferenceChangeListener listener) {
preferences.registerOnSharedPreferenceChangeListener(listener);
}
示例13: registerOnSharedPreferenceChangeListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
_sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
}
示例14: registerOnSharedPreferenceChangedListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerOnSharedPreferenceChangedListener(SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
mPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
示例15: registerListener
import android.content.SharedPreferences; //导入方法依赖的package包/类
public void registerListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
prefs.registerOnSharedPreferenceChangeListener(listener);
}