[英]How to display date (day and month) on each item in RecyclerView android kotlin
I have a fragment
that has a RecyclerView
of six items (meaning every day of the week from Monday to Saturday).我有一个
fragment
,它有六个项目的RecyclerView
(意思是从周一到周六的每一天)。 Is there any way to display the current date (day and month) on all these elements, so that the countdown starts from Monday of the current week?有没有办法在所有这些元素上显示当前日期(日和月),以便从本周的星期一开始倒计时?
You can get this using LocalDate.您可以使用 LocalDate 获取此信息。
val thisWeekMonday = LocalDate.now()
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
val daysOfThisWeek = List(7) { thisWeekMonday + Period.ofDays(it) }
You can use DateTimeFormatter to convert it to a human-readable String for use in your List that you put in the RecyclerView.您可以使用 DateTimeFormatter 将其转换为人类可读的字符串,以便在您放入 RecyclerView 的列表中使用。 For example:
例如:
val formatter = DateTimeFormatter.ofPattern("EEEE, MMMM d")
val formattedDaysOfThisWeek = daysOfThisWeek.map { it.format(formatter) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.