Aakash
Aakash

Reputation: 101

Firebase Recycler Adapter is not showing anything

I am making a fragment where i am showing some data in recyclerview. But it is not showing anything not event the error. I am not using any @PropertyName of firebase Here is my firebase database snap

enter image description here

NewCustomer.java (my module class)

package com.example.lenovo.jdstudio;

import java.util.Map;

public class NewCustomer {
    private String fName, lName, email, phone, photodesc, status;
    private Map time;

    public NewCustomer() {}

    public NewCustomer(String fName, String lName, String email, String phone, String photodesc, String status, Map time) {
        this.fName = fName;
        this.lName = lName;
        this.email = email;
        this.phone = phone;
        this.photodesc = photodesc;
        this.status = status;
        this.time = time;
    }

    public String getfName() {return fName;}

    public String getlName() {return lName;}

    public String getEmail() {return email;}

    public String getPhone() {return phone;}

    public String getPhotodesc() {return photodesc;}

    public String getStatus() {return status;}

    public Map getTime() {return time;}
}

Updaterder.java

public class UpdateOrder extends Fragment {

    private View mView;
    @BindView(R.id.customerDetailsRecyclerView)
    RecyclerView mCustmoerDetails;

    private FirebaseDatabase mDatabase;
    private DatabaseReference mCustomerDatabase;
    private FirebaseRecyclerAdapter firebaseRecyclerAdapter;
    private LinearLayoutManager mManager;
    private static final String TAG = UpdateOrder.class.getSimpleName();
    public UpdateOrder() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mView = inflater.inflate(R.layout.fragment_update_order, container, false);
        ButterKnife.bind(this,mView);

        mCustmoerDetails.setHasFixedSize(true);
        mManager = new LinearLayoutManager(getActivity());
        mCustmoerDetails.setLayoutManager(mManager);

        Log.e(TAG,"Before firebaseoption");

        mDatabase = FirebaseDatabase.getInstance();
        mCustomerDatabase = mDatabase.getReference().child("new_customer");
        FirebaseRecyclerOptions<NewCustomer> options =
                new FirebaseRecyclerOptions.Builder<NewCustomer>().
                        setQuery(mCustomerDatabase,NewCustomer.class).
                        build();

        //        Log.e(TAG,"OnStart");

        firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<NewCustomer, CustDetailHolder> (options){
            @Override
            protected void onBindViewHolder(@NonNull CustDetailHolder holder, int position, @NonNull NewCustomer model) {
                holder.setFname(model.getfName());
                holder.setLname(model.getlName());
                holder.setPhotoDetail(model.getPhotodesc());
            }

            @Override
            public CustDetailHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.single_order_details, parent, false);
                Log.e(TAG,"oncreate is called");

                return new CustDetailHolder(view);
            }
        };
        mCustmoerDetails.setAdapter(firebaseRecyclerAdapter);

        return mView;
    }

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

    }

    @Override
    public void onStop() {
        super.onStop();
        firebaseRecyclerAdapter.stopListening();
    }

    //ViewHolder class
    public static class CustDetailHolder extends RecyclerView.ViewHolder {
        View mView;

        public CustDetailHolder(View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setFname(String  name) {
            TextView FName = (TextView) mView.findViewById(R.id.cust_Fname);
            FName.setText(name);
        }


        public void setLname(String name) {
            TextView LName = (TextView) mView.findViewById(R.id.cust_Lname);
            LName.setText(name);
        }

        public void setPhotoDetail(String photoDetail) {
            TextView photo_details = (TextView) mView.findViewById(R.id.photo_Details);
            photo_details.setText(photoDetail);
        }

        public void setOrderSpinner(String status){

        }
    }


}

single_order_detail.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <LinearLayout
            android:id="@+id/cust_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="@dimen/dimen_15dp">

            <TextView
                android:id="@+id/cust_Fname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Fname"
                android:textSize="16dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/cust_Lname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="3dp"
                android:text="Lname"
                android:textSize="16dp"
                android:textStyle="bold" />

        </LinearLayout>


        <TextView
            android:id="@+id/order_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/cust_name"
            android:paddingLeft="@dimen/dimen_15dp"
            android:paddingTop="@dimen/dimen_10dp"
            android:text="order Status goes here"
            android:textSize="15sp" />

        <Spinner
            android:id="@+id/order_status_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/cust_name"
            android:layout_toRightOf="@id/order_status"
            />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/order_status"
            android:paddingLeft="15dp"
            android:paddingTop="@dimen/dimen_10dp"
            android:text="Photo Description:"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/photo_Details"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignEnd="@+id/textView"
            android:layout_below="@+id/textView"
            android:paddingRight="@dimen/dimen_15dp"
            android:paddingTop="@dimen/dimen_5dp"
            android:text="4x6 id and passport"
            android:textSize="12sp" />
    </RelativeLayout>

</android.support.v7.widget.CardView>

fragment_update_order.xml

<RelativeLayout 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="com.example.lenovo.jdstudio.UpdateOrder">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/customerDetailsRecyclerView">

    </android.support.v7.widget.RecyclerView>
</RelativeLayout>

Thanks For seeing the post. waiting for the answer. Please correct me if i am doing anything wrong. dont't mark it duplicate without reading it. I have attached all the listener.

Upvotes: 0

Views: 3439

Answers (4)

YHN
YHN

Reputation: 75

I have faced the same problem as you described, thank you for sharing the problem and comments. I followed them and found out that I should remove setHasFixedSize(true) from the recycler view. Also, I should override the onStart and onStop methods with start and stop listening for the adapter, respectively. That has solved my problem of not showing anything on recycler view.

P.S: I am aware that you have found your answer and solved your problem long ago. I am just sharing this conclusion here as it was not directly extractable from the discussion.

Upvotes: 4

Jaloliddin Bieber
Jaloliddin Bieber

Reputation: 39

Man maybe your forgot to call firebaseRecyclerAdapter.startListening in your @override onStart(){}

Upvotes: 0

Peter Haddad
Peter Haddad

Reputation: 80944

The strings in your model class:

fName
lName

must be the same as in your database, in your database you have this:

FName
LName

For Anyone Checking this:

It was solved as I said in my comment:

@Aakash keep it, but put this instead mCustmoerDetails.setHasFixedSize(false) – Peter Haddad yesterday

OP had to add mCustmoerDetails.setHasFixedSize(false) instead of mCustmoerDetails.setHasFixedSize(true)

or remove mCustmoerDetails.setHasFixedSize(true)

Upvotes: 0

Alex Mamo
Alex Mamo

Reputation: 139039

As I see in your database, your fields do not corespond to those from your model class. To solve this, delete the old data, add fresh one and your problem will be solved.

As I see in your code, you are using for the declaration of your CustDetailHolder class, the static keyword, which is wrong. You only need:

public class CustDetailHolder extends RecyclerView.ViewHolder

Also remove ButterKnife.bind(this,mView); as I see that you don't use it in your code.

Upvotes: 2

Related Questions