Skip to content

Commit 127c5be

Browse files
committed
project #7: restriction for selecting future dates
1 parent aff438d commit 127c5be

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

AgeInMinutes/app/src/main/java/com/example/ageinminutes/MainActivity.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MainActivity : AppCompatActivity() {
3232
val day = myCalendar.get(Calendar.DAY_OF_MONTH)
3333

3434
//open date picker popup
35-
DatePickerDialog(
35+
val datePicker = DatePickerDialog(
3636
this,
3737
DatePickerDialog.OnDateSetListener { view, selectedYear, selectedMonth, selectedDayOfMonth ->
3838
// assign the user input in the variable and format the view
@@ -65,6 +65,10 @@ class MainActivity : AppCompatActivity() {
6565
year,
6666
month,
6767
day
68-
).show()
68+
)
69+
// restriction for the future date selection
70+
datePicker.datePicker.maxDate = Date().time - 86400000
71+
// visible the date picker
72+
datePicker.show()
6973
}
7074
}

0 commit comments

Comments
 (0)