代码:
public class SettingsActivity extends PreferenceActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(PreferencesChanged);
}
SharedPreferences.OnSharedPreferenceChangeListener PreferencesChanged = new
SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
Toast.makeText(this, "changed", Toast.LENGTH_LONG).show();
}
};
}
答案:如果更改了任何选项(一次点击),文本会出现两次: - /这是正常的吗? “OnSharedPreferenceChangeListener”发送双回调吗?我如何防止双重回调?