简体   繁体   English

如何在 RecyclerView android kotlin 中的每个项目上显示日期(日和月)

[英]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.

相关问题 如何在Kotlin(Android)中的日期选择器对话框中仅显示日期和月份? - How to show only day and month in date picker dialog in Kotlin(Android)? 如何在kotlin / android ..中仅显示时间而不是日期,月份,时间和GMT? - How to display just the time instead of day,month,time and GMT in kotlin/android..? 如何使用 Kotlin 在 RecyclerView 中显示所选项目的项目信息 - How to display item info on selected item in RecyclerView using Kotlin 更改 Android DatePickerDialog 中日期、日和月的显示格式 - change Display format of Date, day and month in Android DatePickerDialog 项目Onclick RecyclerView Kotlin Android - Item Onclick RecyclerView Kotlin Android 使用 Android Studio,如何从 Datepicker 中选择的日期显示日(星期一、星期二、星期三等)、日期、月份和年份 - Using Android Studio, how to display Day(mon,tue,wed etc.), Date, Month and Year from selected date in Datepicker Android,Kotlin:Recyclerview,如何防止显示最后一项,但将其传递给适配器 - Android, Kotlin: Recyclerview, how to prevent the last item to be shown, but pass it to the adapter 如何在Android RecyclerView中显示一组项目的日期/日期 - How to show day/date above of a group of items in Android RecyclerView 如何使用 Kotlin、Firebase android studio 将时间戳转换为 recyclerview 的日期 - how to convert timestamp to date for recyclerview using Kotlin, Firebase android studio 如何在kotin(FireStore)中将每个数组项显示到recyclerview - how to display each array item to recyclerview in kotin (FireStore)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM