等效于 RecyclerView 中的 ListView.setEmptyView [英] Equivalent of ListView.setEmptyView in RecyclerView

查看:20
本文介绍了等效于 RecyclerView 中的 ListView.setEmptyView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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&lt;java.lang.String&gt;"
    />
</data>

这篇关于等效于 RecyclerView 中的 ListView.setEmptyView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆