Android Firestore RecyclerView未显示应用程序中的项目

Android Firestore RecyclerView未显示应用程序中的项目,android,firebase,android-studio,android-recyclerview,google-cloud-firestore,Android,Firebase,Android Studio,Android Recyclerview,Google Cloud Firestore,我正在使用firestore recyclerview,但应用程序上不会显示这些项目。我不知道是什么问题。我以前在其他项目中没有使用过,但我仍然没有犯过错误 显示片段: import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.anno

我正在使用firestore recyclerview,但应用程序上不会显示这些项目。我不知道是什么问题。我以前在其他项目中没有使用过,但我仍然没有犯过错误

显示片段:

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;

import butterknife.BindView;
import butterknife.ButterKnife;


public class HospitalFragment extends Fragment {

    @BindView(R.id.hospitalList)
    RecyclerView hospitalList;

    CollectionReference medcenters;
    FirebaseFirestore ref;

    HospitalAdapter hospitalAdapter;

    private String TAG="TAG";

    public HospitalFragment() {
        // Required empty public constructor
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_hospital, container, false);
        ButterKnife.bind(this,view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Log.e(TAG, "onViewCreated: "+hospitalList);

        rvSetUp();
        dbSetup();
    }

    private void dbSetup() {
        ref=FirebaseFirestore.getInstance();
        medcenters=ref.collection("MedicalCenters");
        Query query=medcenters.orderBy("name");
        FirestoreRecyclerOptions<RVCell> options=new FirestoreRecyclerOptions.Builder<RVCell>()
                .setQuery(query,RVCell.class)
                .build();
        hospitalAdapter=new HospitalAdapter(options,getContext());
        hospitalList.setAdapter(hospitalAdapter);
    }

    private void rvSetUp() {

        hospitalList.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager=new LinearLayoutManager(getContext());
        hospitalList.setLayoutManager(layoutManager);
    }

    @Override
    public void onStart() {
        super.onStart();
        hospitalAdapter.startListening();
    }

    @Override
    public void onStop() {
        super.onStop();
        hospitalAdapter.stopListening();
    }
}
主要布局。回收视图布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HospitalFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/hospitalList"/>

</FrameLayout>

单元布局。这是用于在“回收器”视图中显示项目的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Location"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/container"
        android:background="@color/card_bg_color" />

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:background="@drawable/card_bg"
        android:paddingBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@+id/location"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/title"
            android:layout_alignStart="@+id/title"
            android:layout_alignLeft="@id/title"
            android:layout_marginTop="8dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Location:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/location"
            android:layout_alignStart="@+id/location"
            android:layout_alignLeft="@id/location"
            android:layout_marginTop="8dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Time:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/phno"
            android:layout_width="333dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/location"
            android:layout_alignStart="@+id/time"
            android:layout_alignLeft="@id/time"
            android:layout_marginStart="-2dp"
            android:layout_marginLeft="-2dp"
            android:layout_marginTop="34dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Phone:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="40dp"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="20dp"
            android:text="Simple Title Text "
            android:textColor="@color/colorPrimary"
            android:textStyle="bold" />

    </RelativeLayout>

    <ImageView
        android:id="@+id/img_user"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintEnd_toStartOf="@+id/container"
        app:layout_constraintStart_toStartOf="@+id/container"
        app:layout_constraintTop_toTopOf="@+id/container"
        app:srcCompat="@mipmap/ic_launcher" />

</androidx.constraintlayout.widget.ConstraintLayout>


这就是代码。我找了很多,没有发现任何错误。我还使用了回收器适配器的侦听器。如果有人能帮上忙,那就太好了。

哪些信息有你的标签? 它必须有您的活动名称,请尝试以下操作:


私有静态最终字符串标记=“HospitalFragment”

请将您的数据库结构添加为屏幕截图和
RVCell
类的内容。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".HospitalFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/hospitalList"/>

</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp">

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Location"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/container"
        android:background="@color/card_bg_color" />

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:background="@drawable/card_bg"
        android:paddingBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@+id/location"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/title"
            android:layout_alignStart="@+id/title"
            android:layout_alignLeft="@id/title"
            android:layout_marginTop="8dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Location:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/location"
            android:layout_alignStart="@+id/location"
            android:layout_alignLeft="@id/location"
            android:layout_marginTop="8dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Time:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/phno"
            android:layout_width="333dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/location"
            android:layout_alignStart="@+id/time"
            android:layout_alignLeft="@id/time"
            android:layout_marginStart="-2dp"
            android:layout_marginLeft="-2dp"
            android:layout_marginTop="34dp"
            android:layout_marginRight="16dp"
            android:lineSpacingExtra="8dp"
            android:text="Phone:"
            android:textColor="@color/content_text_color" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginStart="40dp"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="20dp"
            android:text="Simple Title Text "
            android:textColor="@color/colorPrimary"
            android:textStyle="bold" />

    </RelativeLayout>

    <ImageView
        android:id="@+id/img_user"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintEnd_toStartOf="@+id/container"
        app:layout_constraintStart_toStartOf="@+id/container"
        app:layout_constraintTop_toTopOf="@+id/container"
        app:srcCompat="@mipmap/ic_launcher" />

</androidx.constraintlayout.widget.ConstraintLayout>