gpt4 book ai didi

android - 出生日期限制

转载 作者:行者123 更新时间:2023-12-02 10:34:20 25 4
gpt4 key购买 nike

我想将日期选择器对话框限制为至少选择 18 岁

    val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)

val abc = findViewById<Button>(R.id.birth)


abc.setOnClickListener {
DatePickerDialog(this, DatePickerDialog.OnDateSetListener { view, mYear, mMonth, mDay ->
date.setText("" + mDay +"/" + mMonth +"/" + mYear)
}, year, month, day).show()
}
}

最佳答案

你可以试试这个方法

val calendarMaxDate = Calendar.getInstance()
calendarMaxDate.add(Calendar.YEAR, -18)

val datePickerDialog = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { view, mYear, mMonth, mDay ->
date.setText("" + mDay +"/" + mMonth +"/" + mYear)
}, year, month, day)
datePickerDialog.datePicker.maxDate = calendarMaxDate.timeInMillis
datePickerDialog.show()

关于android - 出生日期限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60309658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com