ListView.setEmptyView的RecyclerView等效 [英] Equivalent of ListView.setEmptyView in RecyclerView
本文介绍了ListView.setEmptyView的RecyclerView等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在RecyclerView,我想设置一个空的观点时,适配器是空的,以显示。是否有<一等效href="http://developer.android.com/reference/android/widget/AdapterView.html#setEmptyView(android.view.View)">ListView.setEmptyView?
In RecyclerView, I want to set an empty view to be shown when the adapter is empty. Is there an equivalent of ListView.setEmptyView?
推荐答案
随着新的数据绑定功能,你也可以直接布局实现这一点:
With the new data binding feature you can also achieve this in your layout directly:
<TextView
android:text="No data to display."
android:visibility="@{dataset.size() > 0 ? View.GONE : View.VISIBLE}" />
在这种情况下,你只需要添加一个变量,并导入到你的XML数据部分:
In that case you just need to add a variable and an import to the data section of your XML:
<data>
<import type="android.view.View"/>
<variable
name="dataset"
type="java.util.List<java.lang.String>"
/>
</data>
这篇关于ListView.setEmptyView的RecyclerView等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文