英文:
android app LocalDate alternative for older API level
问题
我正在构建一个日历应用,在我的代码中主要使用LocalDate
来设置我的RecyclerView
和一些其他功能。我有一台平板电脑,其Android版本为7.1.1,因此无法运行与LocalDate
相关的代码。
我想挑战自己,使我的应用程序能够在最低SDK版本16上运行。是否有任何替代LocalDate
的选项适用于我的代码?我还在我的代码中使用Calendar
,但是对于我的RecyclerView
来说,需要几乎三倍的代码来执行相同的任务。任何其他建议将不胜感激。
英文:
I am building a calendar app and mostly in my code I use LocalDate
to set my RecyclerView
and some more functions.
I have a tablet that it's android version is 7.1.1, so it cant run anything in my code related to LocalDate
.
I want to contest my self and make my app run to min SDK 16. Are there any alternatives for LocalDate
for my code? I also use Calendar
in my code but for my RecyclerView
is almost the triple code to do same task. Any other suggestion would be apreciated.
答案1
得分: 2
如果您想在较低的Android版本中使用Java 8+功能,可以使用以下选项之一:
使用其中之一,您可以在Android API级别< 26中几乎使用java.time
的所有类和函数,包括LocalDate
。
英文:
If you want to have Java 8+ features available in lower Android version, you can use one of the following options:
- import the ThreeTen Android Backport (ABP)
- make use of Android API Desugaring
With (one of) these two, you can use nearly all of the classes and functions of java.time
in Android API Levels < 26, including LocalDate
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论