<android.support.v7.widget.RecyclerView
android:id="@+id/education_recycle_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
This is my current xml layout file for recycle view.
How to handle empty data in recycler view? is it possible when put text to display "no data" in same layout?
Thanks
This is how I do it:
In XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_no_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/empty_text"
android:textAppearance="?android:textAppearanceMedium"
android:visibility="invisible" />
<android.support.v7.widget.RecyclerView
android:id="@+id/education_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layoutManager="LinearLayoutManager" />
</FrameLayout>
and in the Activity
:
if (!data.isEmpty()) {
//if data is available, don't show the empty text
emptyText.setVisibility(View.INVISIBLE);
RecyclerAdapter adapter = new RecyclerAdapter(data); // pass the data to your adapter here
recyclerView.setAdapter(adapter);
} else
emptyText.setVisibility(View.VISIBLE);
Let me know if you need further information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With