繁体   English   中英

如何在 android 中打开日期选择器时设置默认年份(但在滚动年份时需要显示其他年份直到当前年份)

[英]How to set a default year while opening the date picker in android (But while scrolling the year it needs to show other years till current year)

如何在 android 中打开日期选择器时设置默认年份。

我需要将默认日期选择器年份显示为 10 年。 但在滚动时,它需要显示截至当前日期的年份。

我的代码是这样的

datePicker.setMaxDate(DateUtils.addYears(c.getTime(), 0).getTime());

我假设 c 是代表当前时间的日期 object ?

你试过 datePicker.updateDate(c.getYear() + 1900 - 10, c.getMonth(), c.getDate()) 方法吗?

这应该设置正确的日期。 c.getYear() 返回从 1900 开始的当前年份,但是日期选择器需要正常年份(从 0 开始),所以我们添加 1900。我们需要返回 10 年的日期,所以我们减去 10。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM