【问题标题】:Trigger A dialog at specific time?在特定时间触发对话?
【发布时间】:2014-05-22 04:45:52
【问题描述】:

我不知道如何获取系统日期并将其与用户从 DatePicker 提取的日期进行比较。类似的东西:

if (systemtime) = (timePicker) then
show dialog ("This is your birthday")

这是用户领取日期的代码: 私有类 DatePickerFragment 扩展 DialogFragment 实现 DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();

        if(friend == null) {
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            // Create a new instance of DatePickerDialog and return it
            return new DatePickerDialog(getActivity(), this, year, month, day);
        }

        int year = friend.getYear();
        int month = friend.getMonth();
        int day = friend.getDayOfMonth();

        // Create a new instance of DatePickerDialog and return it
        return new DatePickerDialog(getActivity(), this, year, month, day);
    }

    public void onDateSet(DatePicker view, int year, int month, int day) {
        birthday.set(year, month, day);
    }

【问题讨论】:

  • 请学习如何编码而不是复制/粘贴。

标签: android datepicker android-alertdialog datetimepicker timepicker


【解决方案1】:

尝试以下方法:

在警报管理器中设置警报并在警报时间触发未决意图。通过挂起的意图,您可以将活动作为新任务启动,现在您可以将活动的主题设置为对话框。在警报中,您可以指定打开对话活动的具体时间。

【讨论】:

    【解决方案2】:

    我认为您在特定对话框中设置对话框的路径错误。您必须采取待定意图并设置您朋友的生日时间,然后自动生成时间完成对话框。 您不想为此创建服务并每天进行比较。我希望您理解...

    【讨论】:

    • 感谢回复。将有一个“检查生日”按钮,它比较 datePicker 和系统日期的值以显示一个对话框。我很困惑如何完成它。
    • 好的,然后只获取当前日期和您存储的朋友生日日期并进行比较,但首先检查两个日期格式是否相同。
    • 我可以将它们都存储为字符串格式进行比较吗?
    • 可以用这个方法比吗?
    • 反对票保护 boolean checkDateValidity(Date date){ Calendar cal = new GregorianCalendar(date.getYear() + 1900, date.getMonth(), date.getDate(), date.getHours(),日期.getMinutes()); if((cal.getTimeInMillis()-System.currentTimeMillis())
    猜你喜欢
    • 2013-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多