我正在使用Github 库以格式显示时间,TextView
例如现在、昨天、前一段时间......等等。它显示我想要的时间。但问题是,时间并没有像现在在发布时那样改变——它永远保持不变。
postAdapter的模型类
class Post {
private var date: String = ""
constructor(date: Long) {
fun getDate(): String
{
return date
}
//Initialization according to the library
val timeInMillis = System.currentTimeMillis()
val timeAgo = TimeAgo.using(timeInMillis)
//saving the data to firestore
val fStore: FirebaseFirestore = FirebaseFirestore.getInstance()
val post = Post(title, description, date = timeAgo)
fStore.collection("Posts").document()
.set(post)
.addOnSuccessListener{...}
从Firestore
private fun postInfo(title: TextView, description: TextView, date: TextView) {
val postRef = FirebaseFirestore.getInstance().collection("Posts").document()
postRef.get()
.addOnSuccessListener { documentSnapshot ->
if (documentSnapshot != null && documentSnapshot.exists()) {
val post = documentSnapshot.toObject(Post::class.java)
date.text = post?.getDate()
title.text = post?.getTitle()
description.text = post?.getDescription()
}
}
}