我想告诉用户,当他更改首选项窗口中的一个或多个字段时,它已成功更改,但我遇到了一些问题:
listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
// Implementation
Toast.makeText(this,
"You have selected ",
Toast.LENGTH_SHORT).show();
}
};
appPrefs.registerOnSharedPreferenceChangeListener(listener);
但是我收到以下错误:
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new SharedPreferences.OnSharedPreferenceChangeListener(){}, String, int)
谁能告诉我为什么会得到这个?
最佳答案
Toast.makeText(ActivityName.this,
"You have selected ",
Toast.LENGTH_SHORT).show();
您应该使用 Activity 上下文作为第一个参数
关于java - Android toast 更改偏好设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16319080/