在RecyclerView,我想设置一个空的观点时,适配器是空的,以显示。是否有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>