简体   繁体   中英

Android toast on preference change

I want to tell the user that when he has changed one or more fields in the preference window that it was succesfully changed but I am running into some problems:

        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);

however I get the following error:

The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new SharedPreferences.OnSharedPreferenceChangeListener(){}, String, int)

Can anyone tell me why I'm getting this?

Toast.makeText(ActivityName.this,
                    "You have selected ",
                    Toast.LENGTH_SHORT).show();

You should use activity context as the first parameter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM