Manish Mulimani Manish Mulimani - 1 year ago 253
Android Question

Equivalent of ListView.setEmptyView in RecyclerView

In RecyclerView, I want to set an empty view to be shown when the adapter is empty. Is there an equivalent of ListView.setEmptyView?

Answer Source

With the new data binding feature you can also achieve this in your layout directly:

   android:text="No data to display."
   android:visibility="@{dataset.size() > 0 ? View.GONE : View.VISIBLE}" />

In that case you just need to add a variable and an import to the data section of your XML:

<import type="android.view.View"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download