有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用firestoreRecyclerView显示循环progressBar?

我正在我的应用程序中使用FirestoreRecyclerView。我想在
FirestoreRecyclerView正在加载数据,如果在RecyclerView中没有数据显示,则显示TextView,其文本为“未找到数据”。如果有数据要显示,则同时隐藏TextViewProgressBar,并在RecyclerView中显示数据。请指导如何实现这一点


共 (1) 个答案

  1. # 1 楼答案

    可以使用两个布局作为主布局的子布局。 第一个布局包含TextViewProgressBar,其可见性设置为visible

    第二个布局是FirestoreRecyclerView,设置为invisiblegone

    一旦代码接收到该RecyclerView的数据,就隐藏第一个布局并使RecyclerView可见

    下面是一个例子:

    主布局。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);