Im trying to have my datepicker display the predefined date that I have set when I click on it.
I have tried using a delimiter to separate the date and setting them based on the year, month and day but it still does not work. it keeps on displaying the current date instead of the date i set
val date = '03-22-2022'
val startCalendar = Calendar.getInstance()
val startPicker = DatePickerDialog.OnDateSetListener{ view, year, month, dayOfMonth ->
startCalendar.set(Calendar.YEAR,year)
startCalendar.set(Calendar.MONTH,month)
startCalendar.set(Calendar.DAY_OF_MONTH,dayOfMonth)
}
editstartdatepicker.setOnClickListener{
val dialog = DatePickerDialog(this,
startPicker,
startCalendar.get(Calendar.YEAR),
startCalendar.get(Calendar.MONTH),
startCalendar.get(Calendar.DAY_OF_MONTH))
dialog.show()
}
2
Answers
may it helps
You should initialize startCalender as it’s pointing to current date
use this