views:

110

answers:

1

Hi everyone,

In my app I'd like to show a warning when using a certain preference in my application. I've tried using the PreferenceActivity.onPreferenceTreeClick and the onPreferenceClickListener, but neither seems to work. I've got the latter example below. Could anyone shed some light on this please?

@Override
protected void onCreate(Bundle saved) {

    super.onCreate(saved);
    addPreferencesFromResource(R.xml.prefs);
    Preference gridview = findPreference("fcngrid");
    gridview.setOnPreferenceClickListener(overrider);

}

public OnPreferenceClickListener overrider = new OnPreferenceClickListener() {

    public boolean onPreferenceClick(Preference pref) {

        if (pref.getTitle() == "Default as grid")
            showDialog(0);

        return false;
    }

};

protected Dialog onCreateDialog(int id) {

    AlertDialog.Builder b = new AlertDialog.Builder(this);
    b.setTitle("Warning")
     .setMessage("Unfortunately, this feature is currently unstable, and will be" +
             " fixed soon.")
     .setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            dialog.cancel();

        }

     });

    return b.create();

}
+1  A: 

Don't worry, using pref.getTitle().equals("Default as grid") worked fine.

Espiandev
if (pref.getTitle() == "Default as grid") showDialog(0); Mhhhh, maybe this one is better: if (pref== gridview) showDialog(0);
Profete162
Oh yer, didn't think of that! Probably a much better way of doing it. Thanks!
Espiandev