问题
Is there possibility to set a custom date in DatePicker? I want to set a date in DatePicker, and then allow user to edit it. Thanks!
回答1:
Have you seen this tutorial? It says to set the DatePicker initially, use DatePicker.init:
Calendar cal=Calendar.getInstance(Locale.ENGLISH);
dp.init(cal.getTime().getYear()+1900, cal.getTime().getMonth(), cal.getTime().getDay(), this);
回答2:
There's the DatePicker.init where you can set it...
Or to set the date you can use the calendar control as shown in the android developer sample. See Steps 4-6.
Here's another sample blog post on this.
回答3:
final Calendar c = Calendar.getInstance(Locale.ENGLISH);
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
showDialog(DATE_DIALOG_ID);
来源:https://stackoverflow.com/questions/8279898/setting-custom-date-in-datepicker