覆盖android偏好活动中的点击
在我的应用程序中,我想在应用程序中使用特定首选项时显示警告。我尝试过使用 PreferenceActivity.onPreferenceTreeClick 和 onPreferenceClickListener,但似乎都不起作用。我在下面有后一个例子。有人可以解释一下吗?
@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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
别担心,使用
pref.getTitle().equals("Default as grid")
效果很好。Don't worry, using
pref.getTitle().equals("Default as grid")
worked fine.