如何在DatePicker中设置当前日期? [英] How do I set the current date in a DatePicker?

查看:83
本文介绍了如何在DatePicker中设置当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在我的应用程序中选择日期和时间
应该通过使用对话框或开始新的意图来完成。



我现在的方式是,我已经开始了一个新的意图,因为我需要设置日期和时间。



我的问题是我需要在 Datepicker 中设置当前日期(这可以通过 Timepicker 使用 setCurrentHour setCurrentMinute )onCreate,并将其设置为



我在Android API中找不到任何使用 DatePicker 的功能。 / p>

任何人都有建议来解决这个问题?



提前感谢!



编辑:
重要提示: DatePicker TimePicker 必须相同对话/意图

解决方案

直接代码

 code> Calendar c = Calendar.getInstance(); 
int mYear = c.get(Calendar.YEAR);
intmMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dialog =
new DatePickerDialog(this,mDateSetListener,mYear,mMonth,mDay);
dialog.show();


I need to be able to choose date and time in my application It should either be done by using a dialog, or starting a new intent.

The way I have done it now, is that I have started a new intent, since I need to set both date and time.

My problem is that I need to set the current date on the Datepicker (This is possible with the Timepicker using setCurrentHour and setCurrentMinute) onCreate, and set that as a lower boundary.

I can't find any functions in the Android API for doing this with the DatePicker.

Anyone have a suggestion to solve this problem?

Thanks in advance!

Edit: Important: The DatePicker and TimePicker must be in the same dialog/intent

解决方案

Straight to code

Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);

DatePickerDialog dialog =
    new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
dialog.show();

这篇关于如何在DatePicker中设置当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆