gpt4 book ai didi

android - 设置最大日期后无法选择 DatePickerDialog 的最后一天

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:59:15 24 4
gpt4 key购买 nike

在DatePickerDialog 上使用setMaxDate 限制可选择的天数后,最后一天没有变灰但不可选择。提前感谢您的帮助。

private void showDatePickerDialog() {
DateTime dateTime = new DateTime();
DateTime tomorrow = dateTime.plusDays(1);
int year = tomorrow.getYear();
int month = tomorrow.getMonthOfYear() -1; // zero based months
int day = tomorrow.getDayOfMonth();

DateTime thirtyDaysInFuture = dateTime.plusDays(30);

long tomorrowMilliseconds = tomorrow.getMillis();
long futureMilliseconds = thirtyDaysInFuture.getMillis();


Log.d(TAG, "YEAR: " + year + ", MONTH: " + month + ", DAY: " + day);

DatePickerDialog datePickerDialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
Log.d(TAG, i + ", " + i1 + ", " + i2);

}
}, year, month, day);

datePickerDialog.getDatePicker().setMinDate(tomorrowMilliseconds);
datePickerDialog.getDatePicker().setMaxDate(futureMilliseconds);
datePickerDialog.show();
}

最佳答案

我有一个类似的问题,我通过将最大日期的小时、分钟和秒分别设置为 23、59 和 59 来解决它。

DatePickerDialog datePickerDialog = new DatePickerDialog(this, 
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// Add your code here
}
}, year, month, day);

Calendar maxDate = Calendar.getInstance();
maxDate.set(Calendar.HOUR_OF_DAY, 23);
maxDate.set(Calendar.MINUTE, 59);
maxDate.set(Calendar.SECOND, 59);
datePickerDialog.getDatePicker().setMaxDate(maxDate.getTimeInMillis());

关于android - 设置最大日期后无法选择 DatePickerDialog 的最后一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33105398/

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