setting custom date in android date picker

To set a custom date in android date picker, you have to use the Calendar object to set a previous date like following:

static final int DATE_DIALOG_ID = 0;

final Calendar c = Calendar.getInstance();
// setting jun-20-2011
c.set(2011, 5, 20);
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);

mPickDate = (EditText) findViewById(;

new StringBuilder()
// Jan is 0, so add 1
.append(mMonth + 1).append("-")
.append(mYear).append(" "));

mPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {



protected Dialog onCreateDialog(int id) {
switch (id) {
return new DatePickerDialog(this,  mDateSetListener, mYear, mMonth, mDay);

return null;

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>