0

When I tried to use getSharedPreferences(), eclipse gave me the android.Preference.preference.getSharePreferences() one, but not the one from contextWrapper which has 2 arguements. I tried to included the whole name which is android.content.ContextWrapper.getSharedPreferences(null, 0), but still doesn't work, eclipse said cannot make a static reference to a non static one. Any idea? I don't have any problem calling the one with 2 arguments in other class such as activity though.

public class DialogExPreference extends DialogPreference implements DialogInterface.OnClickListener
{
    SharedPreferences settings;
    @Override
    public void onClick(DialogInterface dialog, int which)
    {
        if(which==-1)
        {
            if(!pw1.getText().toString().equals("")&&!pw2.getText().toString().equals(""))
            {

                if(pw1.getText().toString().equals(pw2.getText().toString()))
                {
                     settings =getSharedPreferences();// android.content.ContextWrapper.getSharedPreferences(null, 0);
                     Editor editor = settings.edit();
                     editor.putString("password", pw1.getText().toString());
                     editor.commit();                    


                    Toast.makeText(getContext(), "Password Saved", Toast.LENGTH_SHORT).show();
.....
qwr qwr
  • 1,049
  • 4
  • 22
  • 46

1 Answers1

0

you can check below code might help one thing you can use application context

SharedPreferences preferences = getPreference("name_of_pref",MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("storedInt", storedPreference); // value to store
editor.commit();

Also check link Shared Preferences

Community
  • 1
  • 1
Anand
  • 1,315
  • 1
  • 12
  • 18