我在我的应用程序使用FirestoreRecyclerView
。我想说明ProgressBar
而
FirestoreRecyclerView
加载数据,如果没有数据以RecyclerView
显示则显示TextView
其中有文本“没有发现数据”。如果有数据显示然后隐藏既TextView
和ProgressBar
和显示数据RecyclerView
.Please指导如何实现这一目标?
你可以使用两种布局为主要布局的孩子。第一个布局包含两个TextView
和ProgressBar
其可见性设置为visible
。
然后,第二布局是被设定为FirestoreRecyclerView
或invisible
的gone
。
只要你的代码收到该RecyclerView数据,隐藏第一布局,使RecyclerView可见。
下面是一个例子:
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>
码
//...
//When we received all the data to display in recyclerView, do this
layout_progress.setVisibility(View.GONE);
firestoreRecyclerView.setVisibility(View.VISIBLE);