Piotr
Piotr

Reputation: 1753

Setting custom date in DatePicker

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!

Upvotes: 0

Views: 3825

Answers (3)

Irfan Ali
Irfan Ali

Reputation: 199

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);

Upvotes: 0

Jack
Jack

Reputation: 9252

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);

Upvotes: 1

Kevin LaBranche
Kevin LaBranche

Reputation: 21098

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.

Upvotes: 2

Related Questions