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;

Tagged with:

Filed under: Android

Like this post? Subscribe to my RSS feed and get loads more!