Getting a blank page for Recyclerview

Viewed 9

I have data in the firestore and want to implement that data in an activity but the recyclerview activity is empty. My app is in Material UI. In firestore my parent in for Entree with field as name with string and price with numbers. there are no errors but the recyclerview is empty

This is my Entree.XML file recyclerview is implemented here.

Entree.XML

<?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:id="@+id/entreeActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragment.OrderFragment">

<com.google.android.material.appbar.MaterialToolbar
    android:id="@+id/materialToolbar3"
    android:layout_width="414dp"
    android:layout_height="55dp"
    android:layout_marginStart="1dp"
    android:layout_marginEnd="1dp"
    android:background="@color/black"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.6"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textEntree"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="Entree"
    android:textColor="#FFFFFF"
    android:textSize="34sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toEndOf="@+id/materialToolbar3"
    app:layout_constraintHorizontal_bias="0.17"
    app:layout_constraintStart_toStartOf="@+id/materialToolbar3"
    app:layout_constraintTop_toTopOf="parent" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="415dp"
    android:layout_height="676dp"
    android:layout_marginTop="10dp"
    android:fillViewport="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/materialToolbar3"
    tools:ignore="SpeakableTextPresentCheck">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout_editor_absoluteX="1dp"
            android:id="@+id/recycle_entree"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

list_item_single.xml

<?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:padding="16dp">

    <TextView
        android:id="@+id/list_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="#252424"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/list_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="#333030"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/list_name"
        app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

EntreeModel.java

    package com.example.resturantapp.model;
    
    public class EntreeModel {

    private String name;
    private long price;

    //For Firebase
    public EntreeModel() {
    }

    //to receive the data
    public EntreeModel(String name, long price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getPrice() {
        return price;
    }

    public void setPrice(long price) {
        this.price = price;
    }
}

Entree.java

    package com.example.resturantapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.resturantapp.model.EntreeModel;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;

public class Entree extends AppCompatActivity {

    private RecyclerView recyclerEntree;
    private FirebaseFirestore firebaseFirestore;
    private FirestoreRecyclerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_entree);

        firebaseFirestore = FirebaseFirestore.getInstance();
        recyclerEntree = findViewById(R.id.recycle_entree);

        //Query
        Query query = firebaseFirestore.collection("Entree");

        //RecyclerOption
        FirestoreRecyclerOptions<EntreeModel> options = new FirestoreRecyclerOptions.Builder<EntreeModel>()
                .setQuery(query, EntreeModel.class)
                .build();

        adapter = new FirestoreRecyclerAdapter<EntreeModel, EntreeViewHolder>(options) {

            @NonNull
            @Override
            public EntreeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_single, parent,false);
                return new EntreeViewHolder(view);
            }


            @Override
            protected void onBindViewHolder(@NonNull EntreeViewHolder holder, int position, @NonNull EntreeModel model) {
                holder.list_name.setText(model.getName());
                holder.list_price.setText(model.getPrice() + "");
            }
        };
        //recyclerEntree.setHasFixedSize(true);
        recyclerEntree.setLayoutManager(new LinearLayoutManager(this));
        recyclerEntree.setAdapter(adapter);

    }

    private class EntreeViewHolder extends RecyclerView.ViewHolder {
        private TextView list_name;
        private TextView list_price;

        public EntreeViewHolder(@NonNull View itemView) {
            super(itemView);
            list_name = itemView.findViewById(R.id.list_name);
            list_price = itemView.findViewById(R.id.list_price);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        adapter.stopListening();
    }

    @Override
    public void onStop() {
        super.onStop();
        adapter.stopListening();
    }
}
0 Answers
Related