开发者

Override click in android preferenceactivity

开发者 https://www.devze.com 2023-01-15 14:05 出处:网络
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 s

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

}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消