I'm implementing the DatePicker to prompt the user to select the date. I would like to change the default behavior of the DatePicker dialog so that it lets the user to first select the year.
I already know that by clicking on the year, a new menu opens that allows the user to select the year. I would like it to open automatically first.
I did research this and found this answer: how to select year in datepickerdialog android? In this post it is explained how to create a custom date picker in which you would be able to set the maximum date. However, it doesn't help with opening the year selection menu first.
Is it possible to achieve?
In case someone's interested, the translated code in Kotlin of creating a custom date picker dialog:
val mCustomDatePicker = layoutInflater.inflate(com.example.meet.R.layout.custom_date_picker, null)
var mDatePicker = mCustomDatePicker.findViewById(com.example.meet.R.id.mDatePicker) as DatePicker
mDatePicker.maxDate = (Calendar.getInstance().getTime().getTime())
val mDialog = AlertDialog.Builder(this)
mDialog.setView(mCustomDatePicker)
mDialog.setPositiveButton("OK", object : DialogInterface.OnClickListener {
override fun onClick( dialog: DialogInterface, which: Int) {
// mCalendar.set(mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
// mBirthdayEdit.setText(mFormatDate.format(mCalendar.getTime()));
}
}).setNegativeButton("Cancel", object: DialogInterface.OnClickListener {
@Override
override fun onClick( dialog: DialogInterface, which: Int) {
dialog.dismiss()
}
})
mDialog.create()
mDialog.show()
