-
-
Save codeforfun-jp/68b76f783833bec41972c9a07348da2d to your computer and use it in GitHub Desktop.
How to Create Dialog Series Datepicker - Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDialogFragment : DialogFragment() { | |
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
val dialog = activity?.let { | |
// デフォルトの日付を用意 | |
val c = Calendar.getInstance() | |
val year = c[Calendar.YEAR] | |
val month = c[Calendar.MONTH] | |
val day = c[Calendar.DAY_OF_MONTH] | |
DatePickerDialog(it, null, year, month, day) | |
} | |
return dialog ?: throw IllegalStateException("アクティビティがNullです。") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment