0

I want to set the custom date on caleder.present i am showing the current date,now i want to show the existing date.how to set custom date on calender?

I am using the following code.

 DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        Calendar c = Calendar.getInstance();
                        c.set(Calendar.YEAR, year);
                        c.set(Calendar.MONTH, monthOfYear);
                        c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

                    }
                }, year, month, year);
        dpd.getDatePicker().setMinDate(System.currentTimeMillis());
        dpd.show();
m.v.n.kalyani
  • 730
  • 7
  • 20

2 Answers2

0

Change your constructor, this line:

}, year, month, year);

I don't know why you have two year, but second year is acctually dayOfMonth look into documentation:

DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener listener, int year, int month, int dayOfMonth)

If you want change default date of date picker change this 3 variables, year, month and dayOfMonth to set specific date.

miljon
  • 2,021
  • 1
  • 12
  • 18
0

Use the update method

Calendar now = Calendar.getInstance();   

now.add(Calendar.DATE, -1); 

int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH); // it's zero based
int day = now.get(Calendar.DAY_OF_MONTH);

DatePicker datePicker.updateDate(year, month, day);

Check on official documentation of android here

Guru Teja
  • 127
  • 2
  • 12