如何使用DatePickerDialog为preference如何使用、DatePickerDialog、preference

2023-09-07 10:06:40 作者:风落尘归去

我有preferences工作,我现在用的复选框preference和EditText上preference的组合。我想用DatePickerDialog取代他们中的一个。

I have preferences working and I am using a combination of CheckBoxPreference and EditTextPreference. I would like to replace one of them with a DatePickerDialog.

在我的设置屏幕显示,如果点击preferences之一,我想日期选取器对话框,弹出用户选择一个日期,并保存在preferences采摘日期。我已经看到这项工作的其他应用程序,但我看不出如何做到这一点。

When my settings screen is showing, if you click on one of the preferences, I would like the date picker dialog to pop up for the user to select a date, and save the picked date in preferences. I have seen this work in other apps, but I cannot see how to do this.

我从一个普通视图中的日期选择器对话框工作(按照教程),但我喜欢从preference使用它。

I have the date picker dialog working from a regular view (as per tutorial), but I would to like to use it from a preference.

推荐答案

您需要创建一个自定义的对话preference 集成了 DatePicker的。 这里是显示自定义的对话preference 基于自定义 Col​​orMixer 小工具。

You would need to create a custom DialogPreference incorporating a DatePicker. Here is a project showing a custom DialogPreference based on a custom ColorMixer widget.