Android 继续使用数据绑定更新视图
我使用数据绑定将数据设置为Android 继续使用数据绑定更新视图,android,android-layout,android-databinding,android-livedata,Android,Android Layout,Android Databinding,Android Livedata,我使用数据绑定将数据设置为recyclerview项,并使用@BindingAdapter自定义属性。 现在我想在每秒钟更新textview的文本。textview正在显示一个与时间戳相关的文本(很久以前),我通过传递时间戳创建了一个@BindingAdapter函数,该函数非常适合设置文本的单一时间,但我想在每秒钟更新它 <TextView android:id="@+id/tvTime" android:layout_width="wrap_conten
recyclerview项
,并使用@BindingAdapter
自定义属性。
现在我想在每秒钟更新textview的文本。textview正在显示一个与时间戳相关的文本(很久以前),我通过传递时间戳创建了一个@BindingAdapter
函数,该函数非常适合设置文本的单一时间,但我想在每秒钟更新它
<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"
app:timeago="@{order.DateStamp}"
app:layout_constraintBottom_toTopOf="@id/tvOrderId"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Just now" />
您可以为此使用EchoBind类BindingAdapter 绑定应该是从XML到模型/适配器或从模型/适配器到XML的两种方式
要获得详细的文档,请参考这些&。在哪里调用此函数setTimeAgo()?
@BindingAdapter("timeago")
public static void setTimeAgo(TextView view, long time) {
view.setText(getTimeAgo(time));
}