To set a custom date in android date picker, you have to use the Calendar object to set a previous date like following:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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(R.id.dateDisplay); mPickDate.setText( new StringBuilder() // Jan is 0, so add 1 .append(mMonth + 1).append("-") .append(mDay).append("-") .append(mYear).append(" ")); mPickDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { showDialog(DATE_DIALOG_ID); } }); protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); } return null; } |
Incoming search terms:
- how to insert date android on mysql using datepicker
- android datepicker custom
- android initialize calender to custom date
- android set date datepicker
- get datepicker and save in mysql android
- initialize datepicker android
Tagged with: C Calendar • Calendar Day • Calendar Month • Calendar Object • Calendar Year • Date Picker • Edittext • Int Id • Public Void • Settext • Stringbuilder
Filed under: Android
Like this post? Subscribe to my RSS feed and get loads more!




Leave a Reply