Advertisement
Guest User

DatePickerFragment.kt

a guest
Nov 13th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.81 KB | None | 0 0
  1. class DatePickerFragment : DialogFragment(), DatePickerDialog.OnDateSetListener {
  2.  
  3.     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
  4.         // Use the current date as the default date in the picker
  5.         val c = Calendar.getInstance()
  6.         val year = c.get(Calendar.YEAR)
  7.         val month = c.get(Calendar.MONTH)
  8.         val day = c.get(Calendar.DAY_OF_MONTH)
  9.  
  10.         // Create a new instance of DatePickerDialog and return it
  11.         return DatePickerDialog(activity!!, this, year, month, day)
  12.     }
  13.  
  14.     override fun onDateSet(view: DatePicker, year: Int, month: Int, day: Int) {
  15.         // Do something with the date chosen by the user
  16.         val date_picked = "".plus(day).plus("/").plus(month).plus("/").plus(year)
  17.         (activity as MyActivity).updateDate(date_picked)
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement