I am using FirestoreRecyclerView
in my app. I want to show ProgressBar
while
FirestoreRecyclerView
loading data and if there is not data to show in RecyclerView
then show TextView
which has text "no data found". If there data to show then hide both TextView
and ProgressBar
and show data in RecyclerView
.Please guide how to achieve this?
Asked
Active
Viewed 87 times
0

Akhil Kumar
- 3
- 3
1 Answers
0
You could use two layouts as the child of the main layout.
The first layout contains both TextView
and ProgressBar
and its visibility is set to visible
.
The second layout then is the FirestoreRecyclerView
which is set to invisible
or gone
.
As soon as your code receives data for that RecyclerView, hide the first layout and make the RecyclerView visible.
Here's an example:
MainLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- the progress layout -->
<RelativeLayout
android:id="@+id/layout_progress"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading data"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="0"/>
</RelativeLayout>
<FirestoreRecyclerView
android:id="@+id/firestoreRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</LinearLayout>
Code
//...
//When we received all the data to display in recyclerView, do this
layout_progress.setVisibility(View.GONE);
firestoreRecyclerView.setVisibility(View.VISIBLE);

BEAGLE ENTERTAIN
- 158
- 2
- 9
-
Thanks for reply. But I want to use recyclerview like this https://stackoverflow.com/questions/49277797/how-to-display-data-from-firestore-in-a-recyclerview-with-android – Akhil Kumar Feb 04 '19 at 15:14