Search code examples
androidperformanceandroid-layoutdatepickerandroid-datepicker

Here I had Use a material datepicker, but it is not showing the current year in calendar


I had use a material datepicker, but it is not showing the current year in calendar view Datepicker

 from_date.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flage_from=true;
            flage_to=false;
            datePickerDialog = DatePickerDialog.newInstance(MainActivity.this, Year, Month, Day);
            datePickerDialog.setThemeDark(false);


            datePickerDialog.showYearPickerFirst(false);

            datePickerDialog.setAccentColor(Color.parseColor("#215f8b"));

           // datePickerDialog.setTitle("Select Date");

            datePickerDialog.show(getFragmentManager(), "DatePickerDialog");

        }
    });

This is my code


Solution

  • Try this

    Calendar c = Calendar.getInstance();
    int mYear = c.get(Calendar.YEAR);
    int mMonth = c.get(Calendar.MONTH);
    int mDay = c.get(Calendar.DAY_OF_MONTH);
    
    DatePickerDialog dialog =
        new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
    dialog.show();