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.
精彩评论