I use a DatePicker widget in Android for the user to set a date, and want to get the date value when a confirm button is clicked, how can I do that?
I use a DatePicker widget in Android for the user to set a date, and want to get the date value when a confirm button is clicked, how can I do that?
If you are using Kotlin, you can define an extension function for DatePicker:
fun DatePicker.getDate(): Date {
val calendar = Calendar.getInstance()
calendar.set(year, month, dayOfMonth)
return calendar.time
}
Then, it's just: datePicker.getDate(). As if it had always existed.